httpErrorHandler is the centralized HTTP error handler. It parses the error, returns a response as "text/plain; charset=UTF-8".
()
| 90 | // httpErrorHandler is the centralized HTTP error handler. It parses the error, |
| 91 | // returns a response as "text/plain; charset=UTF-8". |
| 92 | func httpErrorHandler() echo.HTTPErrorHandler { |
| 93 | return func(err error, c echo.Context) { |
| 94 | logger := c.Get("logger").(*slog.Logger) |
| 95 | status, message := ParseError(err) |
| 96 | |
| 97 | c.Response().Header().Add(echo.HeaderContentType, echo.MIMETextPlainCharsetUTF8) |
| 98 | |
| 99 | err = c.String(status, message) |
| 100 | if err != nil { |
| 101 | logger.ErrorContext(c.Request().Context(), fmt.Sprintf("send error response: %s", err.Error())) |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | // latencyMiddleware sets the start time in the [echo.Context] under |
| 107 | // "startTime". Its value will be used later to calculate request latency. |