-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
customize the error return #405
Comments
Have a look at this PR: #397 Is there a specific reason why you would want to customize the message? Will a HTTP 400 suffice? |
I am working at ksyun openapi, we need to let the return format be the same. So we need to customize. https://docs.ksyun.com/read/latest/116/_book/KLSAPI/CancelRecordTask.html |
@jinleileiking , you might be out of luck. gRPC protocol defines its Gateway just turns that into a JSON object. |
@jinleileiking , I think you need to set the HTTPError for |
+1 @tamalsaha Hi, our company is recently trying to build micro services using grpc-gateway, and I'm using HTTPError to handle errors. In this case, the error HTTPError receives is the error from "strconv.ParseInt()". I can not assert that, a ParseInt() error is an InvalidArgument error, and then return a HTTP 4xx. More detail is needed, HTTPError has to know what exactly is happening. |
A workaround I've used is to have server pass the error details via a trailer metadata, the on the grpc-gateway side, override the HTTPError handler to read from the trailer metadata. This doesn't quite work for grpc-gateway side errors; for those I just special cased them in the HTTPError handler. |
I will test lately. |
The return message is:
We should completely customize this return.( Use template?) We should not change the core code. We need a config file ??? to set this line:
|
It seems the way to solve this problem. I will dig into it. |
We should export |
I'm also looking forward to being able to return custom errors, or at the very least, serialize also status details I'm sending from the server. |
@ewang would you be kind to share some code samples? I was also looking at grpc/grpc-go#506. But, I'm interested in reviewing different implementations, especially those involving grpc-gateway. |
gRPC-Go now supports using grpc-gateway/runtime/errors.go Line 81 in e4b8a93
|
I wrote a tiny patch that fixes this in the one case I tried:
Not quite sure what to put in the |
On second thought this probably won't work with |
Fixes grpc-ecosystem#405. If we go with this, that is. In a separate commit, I'll update the generated files. Signed-off-by: Stephan Renatus <[email protected]>
Fixes grpc-ecosystem#405. If we go with this, that is. In a separate commit, I'll update the generated files. Signed-off-by: Stephan Renatus <[email protected]>
Fixes grpc-ecosystem#405. If we go with this, that is. In a separate commit, I'll update the generated files. Signed-off-by: Stephan Renatus <[email protected]>
Fixes grpc-ecosystem#405. If we go with this, that is. In a separate commit, I'll update the generated files. Signed-off-by: Stephan Renatus <[email protected]>
I think this can be closed now that #515 has been merged. |
I do not know #51 whether solve this problem. Let the project member to close this issue. |
I think #515 sufficiently addresses the issue. Let's close it and if there are more things you would like to see in the error response let's open another issue. After all, the default handler now serves the included error, and you can override the error handler. |
Do we have a workaround for this? I think that the issue OP addressed hasn't been resolved. I would like to hide the implementation details from the user. For example, a message like this exposes unnecessary information:
|
Our documentation site contains from more details on how to customize your error handling: https://grpc-ecosystem.github.io/grpc-gateway/docs/customizingyourgateway.html. Join us in #grpc-gateway on gophers slack if you need more help. |
If the input type is error, gateway will return a json.
I need to customize the message. Is there a way ?
the name is int32
The text was updated successfully, but these errors were encountered: