DefaultHTTPErrorHandler does not log
linglingqi007 opened this issue · comments
Issue Description
DefaultHTTPErrorHandler does not record the err returned by handler
Checklist
- Dependencies installed
- No typos
- Searched existing issues and docs
Expected behaviour
![image](https://private-user-images.githubusercontent.com/6560524/301195456-bc93b3df-55ee-412a-a75e-20d6b6276d5c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkwNzMwODcsIm5iZiI6MTcxOTA3Mjc4NywicGF0aCI6Ii82NTYwNTI0LzMwMTE5NTQ1Ni1iYzkzYjNkZi01NWVlLTQxMmEtYTc1ZS0yMGQ2YjYyNzZkNWMucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYyMiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MjJUMTYxMzA3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YmQ0MDNiNDdkMjM3NTIyZjBlZDE1OTliM2IzOGVlMmY5OTk5Y2Y3ZTA0MzMzYmNjMDYwZjU1YzNmMjUwODlmOSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.frWLxiJKoC-UqRrd4pii4NwO0VU0rDiReAh8OOD5yG4)
Actual behaviour
Steps to reproduce
Returns an error in the handler
Working code to debug
package main
func main() {
e := echo.New()
e.GET("/", func(ctx echo.Context) error {
return fmt.Errorf("hello")
})
e.Start(":7123")
}
Version/commit
v4.11.4
DefaultHTTPErrorHandler is not meant to log errors. It is meant to send error responses. It logs errors only for cases when writing the response failed. To log errors use:
- Older logger middleware: https://github.com/labstack/echo/blob/master/middleware/logger.go
- Newer request logger https://github.com/labstack/echo/blob/master/middleware/request_logger.go
DefaultHTTPErrorHandler is not meant to log errors. It is meant to send error responses. It logs errors only for cases when writing the response failed. To log errors use:
- Older logger middleware: https://github.com/labstack/echo/blob/master/middleware/logger.go
- Newer request logger https://github.com/labstack/echo/blob/master/middleware/request_logger.go
The feeling of documentation can be misleading.
![image](https://private-user-images.githubusercontent.com/6560524/301226790-f1a4a361-29e3-4df6-895d-68e35b01caed.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkwNzMwODcsIm5iZiI6MTcxOTA3Mjc4NywicGF0aCI6Ii82NTYwNTI0LzMwMTIyNjc5MC1mMWE0YTM2MS0yOWUzLTRkZjYtODk1ZC02OGUzNWIwMWNhZWQucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYyMiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MjJUMTYxMzA3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NGNkOTE5ZDE1ZDc2NGMxMWJiYjg0ZTQ5MzVkODFlMzFkNTA5NGU2NTg4ODM1ZmY3ZGEwNDJlZDFiZTI2NjEyYiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.ZXm4rf-qcYiszWYOwJVwQ8Zfz8yiUbJsN24pyjpLMv0)
The other part of the tutorial documents both the ERR returned by the handler and the ERR that ultimately sends the response.
But it's actually as you said,It logs errors only for cases when writing the response failed.
I will take a look at Echo docs and see if I can improve things.
Notes for other readers in future:
- Echo error handler docs are found here https://echo.labstack.com/docs/error-handling#custom-http-error-handler
- If anyone wants to improve and/or clarify things in docs, the repo is here https://github.com/labstack/echox