-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Semantics of DefaultHTTPErrorHandler seem wrong when HTTPError.Message is customized && e.Debug #1477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Is an issue really stale if no one has read it or responded? Seems suboptimal. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I'm willing to work on a PR for this, if the team can acknowledge that they agree with my statement that this is a problem. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
That looks like a bug. Sorry for overlooking this issue. As we have no "production" mode identification, e.Debug is used to decide if the error should be returned. @danielbprice Yes, a PR would be welcome! |
I will see what I can do. |
PR #1666 created now. Open for review, will be merged in the next view days. |
…ler-with-debug Fix DefaultHTTPErrorHandler with enabled debug (#1477)
Should be fixed already with #1666 . |
Issue Description
While trying to write a custom HTTP error handler, I discovered a relatively new and seemingly incorrect semantic in the DefaultHTTPErrorHandler. I am still using echo v3, and the old semantic seems to be sensible, while the new one does not:
In the old semantic (I am on v3.3.9), the code does this:
That is to say, if the error is an
HTTPError
, then we use its Code and Message. If the error is some other type of error, then in debug mode, we useerr.Error()
. This seems reasonable. It's useful to rember thatHTTPError.Message
is of typeinterface{}
. And so it is reasonable to pass it anything that could be marshalled to JSON.In the new code, (I am testing with v4.1.13), introduced by commit ed51400 the logic is different:
This means that toggling on Debug ALWAYS overwrites message (which may be a map full of an arbitrary set of things). This seems to run counter to what a developer would reasonably expect.
Checklist
Expected behaviour
e.Debug should not modify the semantics of error messages which have a developer-supplied payload
Actual behaviour
e.Debug now wipes out customized error Message payload
Steps to reproduce
Run server below. Hit endpoint with e.g.
curl http://localhost:9999
Working code to debug
In the above code, if e.Debug is set to False, then curl against this endpoint produces:
{"error":"Bad thing happened","reason":"no one knows why"}
Which seems to be the expected result. But when debug=True, it produces:
"code=500, message=map[error:Bad thing happened reason:no one knows why], internal=\u003cnil\u003e"
Which seems like an unexpected result-- the presence of Debug is changing the error semantics of API. This means that the Debug server can't be used with clients which expect to interpret specific fields from API errors.
Version/commit
4.1.13
The text was updated successfully, but these errors were encountered: