Documentation
¶
Index ¶
- Constants
- func ClientPassErrorDetails() twirp.ClientOption
- func ClientPassTimout() twirp.ClientOption
- func DefaultClientOptions() []twirp.ClientOption
- func DefaultServerOptions() []twirp.ServerOption
- func ErrorCodeFromGRPC(code codes.Code) twirp.ErrorCode
- func GetHeaders(ctx context.Context) http.Header
- func PassHeadersHandler(h http.Handler) http.Handler
- func RegisterServer(mux *http.ServeMux, s Server)
- func ServerPassErrorDetails() twirp.ServerOption
- func ServerPassTimeout() twirp.ServerOption
- func StatusFromError(err error) (*status.Status, bool)
- func ToError(err error) twirp.Error
- func WithDetailsFrom(dst twirp.Error, src error) twirp.Error
- func WithDetailsFromStatus(dst twirp.Error, st *status.Status) twirp.Error
- func WrapHandler(s Server) http.Handler
- type ErrorMeta
- type Server
Constants ¶
const DetailsMetaKey = "error_details"
DetailsMetaKey is a Twirp error metadata key that is used to pass protobuf-encoded error details.
Variables ¶
This section is empty.
Functions ¶
func ClientPassErrorDetails ¶
func ClientPassErrorDetails() twirp.ClientOption
ClientPassErrorDetails converts Twirp errors to gRPC errors, if possible. This allows passing error details returned via gRPC/PSRPC by the backend server.
func ClientPassTimout ¶
func ClientPassTimout() twirp.ClientOption
ClientPassTimout adds context timeout as a Twirp request header.
func DefaultClientOptions ¶
func DefaultClientOptions() []twirp.ClientOption
DefaultClientOptions returns default Twirp client options.
func DefaultServerOptions ¶
func DefaultServerOptions() []twirp.ServerOption
DefaultServerOptions returns default Twirp server options.
func ErrorCodeFromGRPC ¶
ErrorCodeFromGRPC converts gRPC error code to Twirp.
func GetHeaders ¶
GetHeaders returns Twirp headers from the context.
func PassHeadersHandler ¶
PassHeadersHandler wraps Twirp server handler to allow passing HTTP headers in the context.
func RegisterServer ¶
RegisterServer registers Twirp server on an HTTP mux. It also calls WrapHandler to add default middleware.
func ServerPassErrorDetails ¶
func ServerPassErrorDetails() twirp.ServerOption
ServerPassErrorDetails converts gRPC errors to Twirp errors. It properly converts gRPC/PSRPC error codes and preserves custom error details.
func ServerPassTimeout ¶
func ServerPassTimeout() twirp.ServerOption
ServerPassTimeout uses context timeout from Twirp request header. It requires that Twirp server handler is wrapped with PassHeadersHandler.
func StatusFromError ¶
StatusFromError is an analog of gRPCs status.FromError, but it also considers error details encoded in Twirp metadata.
func WithDetailsFrom ¶
WithDetailsFrom sets gRPC/PSRPC error details from src as Twirp error metadata on dst.
If error details implement ErrorMeta, their custom metadata fields will be included as well.
func WithDetailsFromStatus ¶
WithDetailsFromStatus sets gRPC error details from status as Twirp error metadata on dst.
If error details implement ErrorMeta, their custom metadata fields will be included as well.
func WrapHandler ¶
WrapHandler wraps the Twirp server handler with our custom middleware.