chore: centralized error formatting#866
Conversation
|
You can access the deployment of this PR at https://renku-ci-gw-866.dev.renku.ch |
|
To check this: Open the browser at: https://renku-ci-gw-866.dev.renku.ch/api/fdfd - this will give you the same response as before. We can add a nice http page for the errors later. We need to coordinate with the ui for this. But if you use curl you will get the same format as the data service. |
|
With using python we also get the non-http response: |
| ) | ||
|
|
||
| // The same error content as the data services API | ||
| const gwBaseErrorCode int = 6000 |
There was a problem hiding this comment.
Why 6000? (Do we have a rule for these numbers?)
| accept := c.Request().Header.Get("Accept") | ||
| isHTML := strings.Contains(accept, echo.MIMETextHTML) |
There was a problem hiding this comment.
Remark: weak content negotiation. But there is no standard library method to at least parse the accept header (not even try to perform content negotiation).
See: https://httpwg.org/specs/rfc9110.html#field.accept
| if c.Request().Method == http.MethodHead { | ||
| cErr = c.NoContent(code) | ||
| } else { | ||
| cErr = c.JSON(code, errorResponse{Error: errorContent{Code: gwBaseErrorCode + code, Message: message}}) |
There was a problem hiding this comment.
It looks like we are not using Detail and TraceId. Should we open an issue to add them?
| cErr = c.JSON(code, errorResponse{Error: errorContent{Code: gwBaseErrorCode + code, Message: message}}) | ||
| } | ||
| if cErr != nil { | ||
| c.Logger().Error("failed to send error page to client", "error", errors.Join(err, cErr)) |
There was a problem hiding this comment.
Use slog.Error() here. We configure the logger for slog but we don't set the Logger used by echo.
There was a problem hiding this comment.
Note: maybe this file should be in internal/gwerrors/?
/deploy