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

Support HTTP-style error codes from GRPC errors #40

Merged
merged 5 commits into from
May 31, 2017
Merged

Conversation

leth
Copy link
Contributor

@leth leth commented May 30, 2017

Adds a new grpc middleware factory for converting errors into http-style error objects, and updates the existing grpc prometheus middleware to understand that.

There's a new test covering the GRPC server to test this error handling.

I split out the httpgrpc server code to fix a circular import.

Marcus Cobden added 2 commits May 30, 2017 13:19
One thing must be broken out to prevent circular imports, this seemed
nicer.
@leth leth requested a review from tomwilkie May 30, 2017 12:50
s, ok := status.FromError(err)
if !ok {
fmt.Println("not status")

This comment was marked as abuse.

status = "error"
errInfo, ok := status.FromError(err)
if ok {
respStatus = strconv.Itoa(int(errInfo.Code()))

This comment was marked as abuse.

}

// ErrorToStatus handler to convert error objects to http-response errors
type ErrorToStatus func(error) (code int32, message string, err error)

This comment was marked as abuse.

@tomwilkie
Copy link
Contributor

LGTM with a few minor nits.

@tomwilkie
Copy link
Contributor

Also, can we have a helper function in line with http.Error? https://golang.org/pkg/net/http/#Error

@tomwilkie
Copy link
Contributor

Even better, an Errorf

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

Successfully merging this pull request may close these issues.

2 participants