Set HTTP error handler
This commit is contained in:
parent
be14524c33
commit
23e3e85251
1 changed files with 11 additions and 0 deletions
11
server.go
11
server.go
|
@ -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}
|
||||
|
|
Loading…
Reference in a new issue