Skip to content

Commit

Permalink
chore: fix logging message
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Oct 20, 2024
1 parent b63c8c2 commit 5ce009f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions web/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@ func getDefaultErrorHandler() echo.HTTPErrorHandler {
WithOptions(zap.AddStacktrace(zapcore.PanicLevel), zap.WithCaller(false))

return func(err error, c echo.Context) {
reqID := c.Request().Header.Get(cf.HeaderRequestID)

{
var e res.HTTPError
if errors.As(err, &e) {
// handle expected http error
_ = c.JSON(e.Code, res.Error{
Title: http.StatusText(e.Code),
Description: e.Msg,
RequestID: c.Request().Header.Get(cf.HeaderRequestID),
RequestID: reqID,
Details: util.Detail(c),
})
return
Expand All @@ -63,15 +65,16 @@ func getDefaultErrorHandler() echo.HTTPErrorHandler {
log.Error("unexpected echo error",
zap.Int("code", e.Code),
zap.Any("message", e.Message),
zap.String("path", c.Request().URL.Path),
zap.String("query", c.Request().URL.RawQuery),
zap.String("cf-ray", c.Request().Header.Get(cf.HeaderRequestID)),
zap.String("request_method", c.Request().Method),
zap.String("request_uri", c.Request().URL.Path),
zap.String("request_query", c.Request().URL.RawQuery),
zap.String("request_id", reqID),
)

_ = c.JSON(http.StatusInternalServerError, res.Error{
Title: http.StatusText(e.Code),
Description: e.Error(),
RequestID: c.Request().Header.Get(cf.HeaderRequestID),
RequestID: reqID,
Details: util.DetailWithErr(c, err),
})
return
Expand All @@ -84,7 +87,7 @@ func getDefaultErrorHandler() echo.HTTPErrorHandler {
zap.String("request_method", c.Request().Method),
zap.String("request_uri", c.Request().URL.Path),
zap.String("request_query", c.Request().URL.RawQuery),
zap.String("request_id", c.Request().Header.Get(cf.HeaderRequestID)),
zap.String("request_id", reqID),
)

_ = c.JSON(http.StatusInternalServerError, res.Error{
Expand All @@ -100,7 +103,7 @@ func getDefaultErrorHandler() echo.HTTPErrorHandler {
zap.String("request_method", c.Request().Method),
zap.String("request_uri", c.Request().URL.Path),
zap.String("request_query", c.Request().URL.RawQuery),
zap.String("request_id", c.Request().Header.Get(cf.HeaderRequestID)),
zap.String("request_id", reqID),
)

// unexpected error, return internal server error
Expand Down

0 comments on commit 5ce009f

Please sign in to comment.