Skip to content

Commit ecc01d2

Browse files
committed
Include internal error in http error handler
Signed-off-by: Vishal Rana <[email protected]>
1 parent 09d415c commit ecc01d2

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

echo.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -344,24 +344,28 @@ func (e *Echo) DefaultHTTPErrorHandler(err error, c Context) {
344344
he, ok := err.(*HTTPError)
345345
if ok {
346346
if he.Internal != nil {
347-
err = fmt.Errorf("%v, %v", err, he.Internal)
347+
if herr, ok := he.Internal.(*HTTPError); ok {
348+
he = herr
349+
}
348350
}
349351
} else {
350352
he = &HTTPError{
351-
Code: http.StatusInternalServerError,
353+
Code: http.StatusInternalServerError,
352354
Message: http.StatusText(http.StatusInternalServerError),
353355
}
354356
}
355357
if e.Debug {
356358
he.Message = err.Error()
359+
} else if m, ok := he.Message.(string); ok {
360+
he.Message = Map{"message": m}
357361
}
358362

359363
// Send response
360364
if !c.Response().Committed {
361365
if c.Request().Method == http.MethodHead { // Issue #608
362366
err = c.NoContent(he.Code)
363367
} else {
364-
err = c.JSON(he.Code, he)
368+
err = c.JSON(he.Code, he.Message)
365369
}
366370
if err != nil {
367371
e.Logger.Error(err)

0 commit comments

Comments
 (0)