errors

package
v0.0.0-...-70211e5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Code

type Code int

Code represents type of internal error

const (
	// UpstreamConnFailure represents failure to connect to the upstream gRPC service
	UpstreamConnFailure Code = 1
	// ServiceUnresolvable represents failure to resolve a gRPC service to its upstream FQDN
	ServiceUnresolvable Code = 2
	// ServiceNotFound represents a missing gRPC service in an upstream, even though the service resolved to that upstream
	ServiceNotFound Code = 3
	// MethodNotFound represents a missing gRPC method in an upstream
	MethodNotFound Code = 4
	// MessageTypeMismatch represents user provided JSON not matching the message's type
	MessageTypeMismatch Code = 5
	// Unknown represents an unknown internal error
	Unknown Code = 6
	// VersionNotSpecified represents the user not specifying the upstream version when it is required.
	VersionNotSpecified Code = 7
	// VersionUndecidable represents there being multiple upstreams that match the specified (service, version) pair
	VersionUndecidable Code = 8
)

type Error

type Error interface {
	error
	HTTPStatusCode() int
	WriteJSON(w io.Writer) error
}

Error wraps an error and provides utilities to get HTTP status code from the error

type GRPCError

type GRPCError struct {
	StatusCode int        `json:"code"`
	Message    string     `json:"message"`
	Details    []*any.Any `json:"details,omitempty"`
}

GRPCError is an error returned by gRPC upstream

func (*GRPCError) Error

func (e *GRPCError) Error() string

Error satisfies the error interface

func (*GRPCError) HTTPStatusCode

func (e *GRPCError) HTTPStatusCode() int

HTTPStatusCode converts gRPC status codes to HTTP status codes https://github.com/grpc-ecosystem/grpc-gateway/blob/7951e5b80744558ae3363fd792806e1db15e91a4/runtime/errors.go

func (*GRPCError) WriteJSON

func (e *GRPCError) WriteJSON(w io.Writer) error

WriteJSON writes an JSON representation of the gRPC error for responses

type ProxyError

type ProxyError struct {
	Code
	Message string
	Err     error
}

ProxyError represents internal errors

func (*ProxyError) Error

func (e *ProxyError) Error() string

Error satisfies the error interface

func (*ProxyError) HTTPStatusCode

func (e *ProxyError) HTTPStatusCode() int

HTTPStatusCode returns the HTTP status code for a internal error

func (*ProxyError) WriteJSON

func (e *ProxyError) WriteJSON(w io.Writer) error

WriteJSON writes an JSON representation of the internal error for responses

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL