Set HTTP error handler

This commit is contained in:
Simon Ser 2019-12-03 13:17:51 +01:00
parent be14524c33
commit 23e3e85251
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48

View file

@ -162,6 +162,17 @@ func New(imapURL string) *echo.Echo {
e.Logger.Fatal(err)
}
e.HTTPErrorHandler = func(err error, c echo.Context) {
code := http.StatusInternalServerError
if he, ok := err.(*echo.HTTPError); ok {
code = he.Code
} else {
c.Logger().Error(err)
}
// TODO: hide internal errors
c.String(code, err.Error())
}
e.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
return func(ectx echo.Context) error {
ctx := &context{Context: ectx, server: s}