-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
use error value for bad URI so custom error handler could treat it special #932
use error value for bad URI so custom error handler could treat it special #932
Conversation
Codecov Report
@@ Coverage Diff @@
## master #932 +/- ##
==========================================
+ Coverage 53.53% 53.81% +0.28%
==========================================
Files 40 40
Lines 3964 3954 -10
==========================================
+ Hits 2122 2128 +6
+ Misses 1645 1630 -15
+ Partials 197 196 -1
Continue to review full report at Codecov.
|
This seems eminently reasonable. Would you be willing to add a test or two to confirm the differentiation between a 404 not found and a 404 unimplemented? |
@achew22, I added tests. PTAL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
…ecial (grpc-ecosystem#932) * use error value for bad URI; so custom error handler could treat it special * add test for ErrUnknownURI being distinct from other 'unimplemented' errors * use status.Convert instead of status.FromError
When a custom
ProtoErrorHandlerFunc
is used, it is given an error withUnimplemented
gRPC code for cases where the server gets a request for an unrecognized URI path.When no such handler is in place, it defaults to a "404 Not Found" error, which is what basically any REST client actually expect for such an error.
Unfortunately, there is not currently any way to distinguish between "the server received an unrecognized URI path" and an actual "Unimplemented" error returned by a gRPC server handler. So it is not possible for a custom handler to turn those into "404 NotFound" errors, as a REST client would actually expect.
This change hoists the error out into an exported error value:
ErrUnknownURI
. That way, a custom error handler can check iferr == runtime.ErrUnknownURI
and choose to return a 404 for those errors (instead of "501 Not Implemented", which can be used for other errors with an "Unimplemented" gRPC code).