[MM-45991] Check and return JSON errors (#20735)

Этот коммит содержится в:
Tim Scheuermann
2022-08-10 11:56:58 +03:00
коммит произвёл GitHub
родитель fdee1df6fe
Коммит 1738bd6e92
65 изменённых файлов: 2068 добавлений и 1938 удалений

Просмотреть файл

@@ -241,8 +241,8 @@ func (c *Context) SetInvalidRemoteClusterTokenError() {
c.Err = NewInvalidRemoteClusterTokenError()
}
func (c *Context) SetJSONEncodingError() {
c.Err = NewJSONEncodingError()
func (c *Context) SetJSONEncodingError(err error) {
c.Err = NewJSONEncodingError(err)
}
func (c *Context) SetCommandNotFoundError() {
@@ -294,9 +294,9 @@ func NewInvalidRemoteClusterTokenError() *model.AppError {
return err
}
func NewJSONEncodingError() *model.AppError {
err := model.NewAppError("Context", "api.context.json_encoding.app_error", nil, "", http.StatusInternalServerError)
return err
func NewJSONEncodingError(err error) *model.AppError {
appErr := model.NewAppError("Context", "api.context.json_encoding.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
return appErr
}
func (c *Context) SetPermissionError(permissions ...*model.Permission) {

Просмотреть файл

@@ -48,7 +48,7 @@ func authorizeOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
var authRequest *model.AuthorizeRequest
err := json.NewDecoder(r.Body).Decode(&authRequest)
if err != nil || authRequest == nil {
c.SetInvalidParam("authorize_request")
c.SetInvalidParamWithErr("authorize_request", err)
return
}
@@ -241,7 +241,7 @@ func getAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("success")
if err := json.NewEncoder(w).Encode(accessRsp); err != nil {
mlog.Warn("Error writing response", mlog.Err(err))
c.Logger.Warn("Error writing response", mlog.Err(err))
}
}

Просмотреть файл

@@ -50,8 +50,15 @@ func incomingWebhook(c *Context, w http.ResponseWriter, r *http.Request) {
defer func() {
if *c.App.Config().LogSettings.EnableWebhookDebugging {
if c.Err != nil {
payload, _ := json.Marshal(incomingWebhookPayload)
mlog.Debug("Incoming webhook received", mlog.String("webhook_id", id), mlog.String("request_id", c.AppContext.RequestId()), mlog.String("payload", string(payload)))
fields := []mlog.Field{mlog.String("webhook_id", id), mlog.String("request_id", c.AppContext.RequestId())}
payload, err := json.Marshal(incomingWebhookPayload)
if err != nil {
fields = append(fields, mlog.NamedErr("encoding_err", err))
} else {
fields = append(fields, mlog.String("payload", string(payload)))
}
mlog.Debug("Incoming webhook received", fields...)
}
}
}()