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

[v2] expose defaultHTTPErrorHandler (and perhaps defaultStreamErrorHandler) #1576

Closed
Azuka opened this issue Aug 10, 2020 · 4 comments
Closed

Comments

@Azuka
Copy link

Azuka commented Aug 10, 2020

🚀 Feature

runtime.DefaultHTTPError was previously exposed in v1, which allowed a user to use something like:

func init() {
	runtime.HTTPError = defaultHTTPError
}

func defaultHTTPError(ctx context.Context, mux *runtime.ServeMux, marshaler runtime.Marshaler, w http.ResponseWriter, r *http.Request, err error) {

	if err != nil {
		apm.CaptureError(ctx, errors.WithStack(err)).Send()
	}

	runtime.DefaultHTTPError(ctx, mux, marshaler, w, r, err)
}

It is very helpful to capture an error which possibly contains a stack trace right before it gets transformed into a status, and replicating the other things the default http error handler does (e.g. trailers) is non-trivial and would also mean not getting any changes from bug fixes.

I can open a PR (trivial task), but wanted to confirm that's ok.

@johanbrandhorst
Copy link
Collaborator

We don't want to reintroduce the assignment in init as that's a very unidiomatic mechanism rife with issues. Is there any reason you can't use https://github.com/grpc-ecosystem/grpc-gateway/blob/v2/runtime/mux.go#L110?

@Azuka
Copy link
Author

Azuka commented Aug 10, 2020

We don't want to reintroduce the assignment in init as that's a very unidiomatic mechanism rife with issues. Is there any reason you can't use https://github.com/grpc-ecosystem/grpc-gateway/blob/v2/runtime/mux.go#L110?

Actually, I just realized it's currently open (https://github.com/grpc-ecosystem/grpc-gateway/blob/v2/runtime/errors.go#L78), but I'm getting an old version since no new tag/release for v2 has been created since May. #1504 has the change I'm looking for.

@johanbrandhorst
Copy link
Collaborator

I can tag another release candidate :)

@Azuka
Copy link
Author

Azuka commented Aug 10, 2020

Thanks @johanbrandhorst

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