Skip to content
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

Better format for error.message in stream #519

Closed
rinatio opened this issue Jan 10, 2018 · 2 comments
Closed

Better format for error.message in stream #519

rinatio opened this issue Jan 10, 2018 · 2 comments

Comments

@rinatio
Copy link

rinatio commented Jan 10, 2018

If you throw an error in stream gRPC API

return status.Error(codes.NotFound, "Foo Bar");

the grpc-gateway translate it this way:

{"error":{"grpc_code":5,"http_code":404,"message":"rpc error: code = NotFound desc = Foo Bar","http_status":"Not Found"}}

Expected result:

{"error":{"grpc_code":5,"http_code":404,"message":"Foo Bar","http_status":"Not Found"}}

Here's a code that might fix it in runtime/handler.go

func streamChunk(result proto.Message, err error) map[string]proto.Message {
	if err != nil {
		grpcCode := codes.Unknown
		message := err.Error()
		if s, ok := status.FromError(err); ok {
			grpcCode = s.Code()
			message = s.Message()
		}
		httpCode := HTTPStatusFromCode(grpcCode)
		return map[string]proto.Message{
			"error": &internal.StreamError{
				GrpcCode:   int32(grpcCode),
				HttpCode:   int32(httpCode),
				Message:    message,
				HttpStatus: http.StatusText(httpCode),
			},
		}
	}
    ...
@achew22
Copy link
Collaborator

achew22 commented Jan 10, 2018

I think this is going to be handled by #515. Please reopen if you don't htink that's the case.

@achew22 achew22 closed this as completed Jan 10, 2018
@rinatio
Copy link
Author

rinatio commented Jan 10, 2018

@achew22 Thank you for quick reply. I'm not sure it is the same issue. I will double check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants