-
Notifications
You must be signed in to change notification settings - Fork 926
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unframed grpc service support richer error model (#4231)
Motivation: We want to add another Unframed Grpcerrorhandler to support richer grpc error information [google errors](https://grpc.io/docs/guides/error/) Modifications: - add `ofRichJson()` method to `UnframedGrpcErrorHandler`. Result: - You can have a richer error model as described by [google error model](https://cloud.google.com/apis/design/errors#error_model) eg. - if you throw exceptions like ```java final ErrorInfo errorInfo = ErrorInfo.newBuilder() .setDomain("test") .setReason("Unknown Exception").build(); final com.google.rpc.Status status = com.google.rpc.Status.newBuilder() .setCode(Code.UNKNOWN.getNumber()) .setMessage("Unknown Exceptions Test") .addDetails(Any.pack(errorInfo)) .build(); responseObserver.onError(StatusProto.toStatusRuntimeException(status)); ``` You can use this error handler by doing ``` java sb.service(GrpcService.builder() .addService(grpcService) .unframedGrpcErrorHandler(UnframedGrpcErrorHandler.ofRichJson()) .build()); ``` You can get a response ``` { "error": { "code": 500, "status": "UNKNOWN", "message": "Unknown Exceptions Test", "details": [{ "@type": "type.googleapis.com/google.rpc.ErrorInfo", "reason": "Unknown Exception", "domain": "test" }] } } ```
- Loading branch information
Showing
5 changed files
with
589 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.