// HTTPStatusFromCode converts a gRPC error code into the corresponding HTTP response status. // See: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto func HTTPStatusFromCode(code codes.Code) int { … } var HTTPError … var GlobalHTTPErrorHandler … var OtherErrorHandler … // MuxOrGlobalHTTPError uses the mux-configured error handler, falling back to GlobalErrorHandler. func MuxOrGlobalHTTPError(ctx context.Context, mux *ServeMux, marshaler Marshaler, w http.ResponseWriter, r *http.Request, err error) { … } // DefaultHTTPError is the default implementation of HTTPError. // If "err" is an error from gRPC system, the function replies with the status code mapped by HTTPStatusFromCode. // If otherwise, it replies with http.StatusInternalServerError. // // The response body returned by this function is a JSON object, // which contains a member whose key is "error" and whose value is err.Error(). func DefaultHTTPError(ctx context.Context, mux *ServeMux, marshaler Marshaler, w http.ResponseWriter, r *http.Request, err error) { … } // DefaultOtherErrorHandler is the default implementation of OtherErrorHandler. // It simply writes a string representation of the given error into "w". func DefaultOtherErrorHandler(w http.ResponseWriter, _ *http.Request, msg string, code int) { … }