httperror

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2023 License: MIT Imports: 13 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// CodeAccountNotFound when requested account not found
	CodeAccountNotFound = "account_not_found"
	// CodeBadNonce is returned for bad nonce.
	CodeBadNonce = "bad_nonce"
	// CodeConflict is returned whith 409 CONFLICT response code.
	CodeConflict = "conflict"
	// CodeConnection is returned when connection failed.
	CodeConnection = "connection"
	// CodeContentLengthRequired is returned when request does not specify ContentLength.
	CodeContentLengthRequired = "content_length_required"
	// CodeFailedToReadRequestBody is returned when there's an error reading the HTTP body of the request.
	CodeFailedToReadRequestBody = "request_body"
	// CodeForbidden is returned when the client is not authorized to access the resource indicated.
	CodeForbidden = "forbidden"
	// CodeInvalidContentType is returned when request specifies invalid Content-Type.
	CodeInvalidContentType = "invalid_content_type"
	// CodeInvalidJSON is returned when we were unable to parse a client supplied JSON Payload.
	CodeInvalidJSON = "invalid_json"
	// CodeInvalidParam is returned where a URL parameter, or other type of generalized parameters value is invalid.
	CodeInvalidParam = "invalid_parameter"
	// CodeInvalidRequest is returned when the request validation failed.
	CodeInvalidRequest = "invalid_request"
	// CodeMalformed is returned when the request was malformed.
	CodeMalformed = "malformed"
	// CodeNotFound is returned when the requested URL doesn't exist.
	CodeNotFound = "not_found"
	// CodeNotReady is returned when the service is not ready to serve
	CodeNotReady = "not_ready"
	// CodeRateLimitExceeded is returned when the client has exceeded their request allotment.
	CodeRateLimitExceeded = "rate_limit_exceeded"
	// CodeRequestFailed is returned when an outbound request failed.
	CodeRequestFailed = "request_failed"
	// CodeRequestTooLarge is returned when the client provided payload is larger than allowed for the particular resource.
	CodeRequestTooLarge = "request_too_large"
	// CodeTimeout is returned when request timed out.
	CodeTimeout = "timeout"
	// CodeTooEarly is returned when the client makes requests too early.
	CodeTooEarly = "too_early"
	// CodeUnauthorized is for unauthorized access.
	CodeUnauthorized = "unauthorized"
	// CodeUnexpected is returned when something went wrong.
	CodeUnexpected = "unexpected"
)

Variables

This section is empty.

Functions

func CorrelationID

func CorrelationID(err error) string

CorrelationID returns correlation ID from GRPC error

func GRPCCode

func GRPCCode(err error) codes.Code

GRPCCode returns gRPC error code

func GRPCMessage

func GRPCMessage(err error) string

GRPCMessage returns gRPC error description

func HTTPStatusFromRPC

func HTTPStatusFromRPC(c codes.Code) int

HTTPStatusFromRPC returns HTTP status

func IsInvalidModel

func IsInvalidModel(err error) bool

IsInvalidModel returns true, if error is InvalidModel

func IsInvalidRequestError

func IsInvalidRequestError(err error) bool

IsInvalidRequestError returns true for Invalid request error

func IsSQLNotFoundError

func IsSQLNotFoundError(err error) bool

IsSQLNotFoundError returns true, if error is NotFound

func IsTimeout

func IsTimeout(err error) bool

IsTimeout returns true for timeout error

func Status

func Status(err error) int

Status returns HTTP status from error

Types

type Error

type Error struct {
	// HTTPStatus contains the HTTP status code that should be used for this error
	HTTPStatus int `json:"-"`

	RPCStatus codes.Code `json:"-"`

	// Code identifies the particular error condition [for programatic consumers]
	Code string `json:"code"`

	// RequestID identifies the request ID
	RequestID string `json:"request_id,omitempty"`

	// Message is an textual description of the error
	Message string `json:"message"`
	// contains filtered or unexported fields
}

Error represents a single error from API.

func AccountNotFound

func AccountNotFound(msgFormat string, vals ...interface{}) *Error

AccountNotFound returns Error instance with AccountNotFound code

func BadNonce

func BadNonce(msgFormat string, vals ...interface{}) *Error

BadNonce returns Error instance with BadNonce code

func Conflict

func Conflict(msgFormat string, vals ...interface{}) *Error

Conflict returns Error instance with Conflict code

func ContentLengthRequired

func ContentLengthRequired() *Error

ContentLengthRequired returns Error instance with ContentLengthRequired code

func FailedToReadRequestBody

func FailedToReadRequestBody(msgFormat string, vals ...interface{}) *Error

FailedToReadRequestBody returns Error instance with FailedToReadRequestBody code

func Forbidden

func Forbidden(msgFormat string, vals ...interface{}) *Error

Forbidden returns Error instance with Forbidden code

func FromOAuth

func FromOAuth(code, descr string) *Error

FromOAuth returns an error with HTTP status code and description

func InvalidContentType

func InvalidContentType(msgFormat string, vals ...interface{}) *Error

InvalidContentType returns Error instance with InvalidContentType code

func InvalidJSON

func InvalidJSON(msgFormat string, vals ...interface{}) *Error

InvalidJSON returns Error instance with InvalidJSON code

func InvalidParam

func InvalidParam(msgFormat string, vals ...interface{}) *Error

InvalidParam returns Error instance with InvalidParam code

func InvalidRequest

func InvalidRequest(msgFormat string, vals ...interface{}) *Error

InvalidRequest returns Error instance with InvalidRequest code

func Malformed

func Malformed(msgFormat string, vals ...interface{}) *Error

Malformed returns Error instance with Malformed code

func New

func New(status int, code string, msgFormat string, vals ...interface{}) *Error

New returns Error instance, building the message string along the way

func NewFromCtx

func NewFromCtx(ctx context.Context, status int, code string, msgFormat string, vals ...interface{}) *Error

NewFromCtx returns Error instance, building the message string along the way

func NewFromPb

func NewFromPb(err error) *Error

NewFromPb returns Error instance, from gRPC error

func NewGrpc

func NewGrpc(code codes.Code, msgFormat string, vals ...interface{}) *Error

NewGrpc returns new GRPC error

func NewGrpcFromCtx

func NewGrpcFromCtx(ctx context.Context, code codes.Code, msgFormat string, vals ...interface{}) *Error

NewGrpcFromCtx returns new GRPC error

func NotFound

func NotFound(msgFormat string, vals ...interface{}) *Error

NotFound returns Error instance with NotFound code

func NotReady

func NotReady(msgFormat string, vals ...interface{}) *Error

NotReady returns Error instance with NotReady code

func RateLimitExceeded

func RateLimitExceeded(msgFormat string, vals ...interface{}) *Error

RateLimitExceeded returns Error instance with RateLimitExceeded code

func RequestTooLarge

func RequestTooLarge(msgFormat string, vals ...interface{}) *Error

RequestTooLarge returns Error instance with RequestTooLarge code

func Timeout

func Timeout(msgFormat string, vals ...interface{}) *Error

Timeout returns Error instance with RequestTimeout code

func TooEarly

func TooEarly(msgFormat string, vals ...interface{}) *Error

TooEarly returns Error instance with TooEarly code

func Unauthorized

func Unauthorized(msgFormat string, vals ...interface{}) *Error

Unauthorized returns Error instance with Unauthorized code

func Unexpected

func Unexpected(msgFormat string, vals ...interface{}) *Error

Unexpected returns Error instance with Unexpected code

func Wrap

func Wrap(err error, msgAndArgs ...any) *Error

Wrap returns Error instance with NotFound, Timeout or Internal code, depending on the error from DB

func WrapWithCtx

func WrapWithCtx(ctx context.Context, err error, msgAndArgs ...any) *Error

WrapWithCtx returns wrapped Error with Context

func (*Error) Cause

func (e *Error) Cause() error

Cause returns original error

func (*Error) CorrelationID

func (e *Error) CorrelationID() string

CorrelationID implements the Correlation interface, and returns request ID

func (*Error) Error

func (e *Error) Error() string

Error implements the standard error interface

func (*Error) GRPCStatus

func (e *Error) GRPCStatus() *status.Status

GRPCStatus returns gRPC status

func (*Error) Is

func (e *Error) Is(target error) bool

Is implements future error.Is functionality. A Error is equivalent if the code and message are identical.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns unwrapped error

func (*Error) WithCause

func (e *Error) WithCause(err error) *Error

WithCause adds the cause error

func (*Error) WithContext

func (e *Error) WithContext(ctx context.Context) *Error

WithContext adds the context

func (*Error) WriteHTTPResponse

func (e *Error) WriteHTTPResponse(w http.ResponseWriter, r *http.Request)

WriteHTTPResponse implements how to serialize this error into a HTTP Response

type ManyError

type ManyError struct {
	// HTTPStatus contains the HTTP status code that should be used for this error
	HTTPStatus int `json:"-"`

	RPCStatus codes.Code `json:"-"`

	// Code identifies the particular error condition [for programatic consumers]
	Code string `json:"code,omitempty"`

	// RequestID identifies the request ID
	RequestID string `json:"request_id,omitempty"`

	// Message is an textual description of the error
	Message string `json:"message,omitempty"`

	Errors map[string]*Error `json:"errors,omitempty"`
	// contains filtered or unexported fields
}

ManyError identifies many errors from API.

func NewMany

func NewMany(status int, code string, msgFormat string, vals ...interface{}) *ManyError

NewMany builds new ManyError instance, build message string along the way

func (*ManyError) Add

func (m *ManyError) Add(key string, err error) *ManyError

Add a single error to ManyError

func (*ManyError) Cause

func (m *ManyError) Cause() error

Cause returns original error

func (*ManyError) CorrelationID

func (m *ManyError) CorrelationID() string

CorrelationID implements the Correlation interface, and returns request ID

func (*ManyError) Error

func (m *ManyError) Error() string

func (*ManyError) GRPCStatus

func (m *ManyError) GRPCStatus() *status.Status

GRPCStatus returns gRPC status

func (*ManyError) HasErrors

func (m *ManyError) HasErrors() bool

HasErrors check if ManyError has any nested error associated with it.

func (*ManyError) WithCause

func (m *ManyError) WithCause(err error) *ManyError

WithCause adds the cause error

func (*ManyError) WriteHTTPResponse

func (m *ManyError) WriteHTTPResponse(w http.ResponseWriter, r *http.Request)

WriteHTTPResponse implements how to serialize this error into a HTTP Response

Jump to

Keyboard shortcuts

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