code-annotation icon indicating copy to clipboard operation
code-annotation copied to clipboard

Logg original errors

Open dpordomingo opened this issue 7 years ago • 6 comments

context: https://github.com/src-d/code-annotation/pull/49#discussion_r164770518

When an error is returned by a handler.RequestProcessFunc, the original error should be logged in the STDERR

dpordomingo avatar Jan 30 '18 15:01 dpordomingo

proposal: serializer.NewHTTPError should wrap the original error, so handler.write could log it

dpordomingo avatar Jan 30 '18 15:01 dpordomingo

+1 to the proposal with the wrapper.

Only one small idea, maybe you don't need to change serializer.NewHTTPError (it accepts status and message). Maybe it's better to create serializer.NewError(err error) which will set status to http.InternalServerError and title http.StatusText(InternalServerError).

Feel free to implement it in any other way though!

smacker avatar Jan 30 '18 16:01 smacker

Thank you! More or less, yes, that would be the way I thought.

The only issue I see with setting the serializer.httpError.Status to http.InternalServerError for all errors created with serializer.NewError(err error), is that in some cases we're mapping the passed errors to any different http status (i.e. when strconv.Atoi fails converting the URL part, the error is http.StatusBadRequest instead of http.InternalServerError)

I'll ping you with a short proposal when ready, so we'll be able to discuss based on that :D

dpordomingo avatar Jan 30 '18 16:01 dpordomingo

I checked the source code and it looks like we return correct error everywhere now. For our current use cases when we return not 500 we don't need to log the original error.

The wrapper itself still can be useful though. But because we don't have any place right now where we really need it, I would suggest to move this issue to backlog. @bzz

smacker avatar Feb 09 '18 16:02 smacker

One thing I would propose is to keep the error messages in the log, but remove them from the 500 we send back to the client. Just in case some DB error includes data a user should not see.

carlosms avatar Feb 09 '18 18:02 carlosms

Yeah. I meant to work like that. Misread code. Fix is here: https://github.com/src-d/code-annotation/pull/84

smacker avatar Feb 09 '18 18:02 smacker