httperror

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// AccountNotFound when requested account not found
	AccountNotFound = "account_not_found"
	// BadNonce is returned for bad nonce.
	BadNonce = "bad_nonce"
	// Conflict is returned whith 409 CONFLICT response code.
	Conflict = "conflict"
	// Connection is returned when connection failed.
	Connection = "connection"
	// ContentLengthRequired is returned when request does not specify ContentLength.
	ContentLengthRequired = "content_length_required"
	// FailedToReadRequestBody is returned when there's an error reading the HTTP body of the request.
	FailedToReadRequestBody = "request_body"
	// Forbidden is returned when the client is not authorized to access the resource indicated.
	Forbidden = "forbidden"
	// InvalidContentType is returned when request specifies invalid Content-Type.
	InvalidContentType = "invalid_content_type"
	// InvalidJSON is returned when we were unable to parse a client supplied JSON Payload.
	InvalidJSON = "invalid_json"
	// InvalidParam is returned where a URL parameter, or other type of generalized parameters value is invalid.
	InvalidParam = "invalid_parameter"
	// InvalidRequest is returned when the request validation failed.
	InvalidRequest = "invalid_request"
	// Malformed is returned when the request was malformed.
	Malformed = "malformed"
	// NotFound is returned when the requested URL doesn't exist.
	NotFound = "not_found"
	// NotReady is returned when the service is not ready to serve
	NotReady = "not_ready"
	// RateLimitExceeded is returned when the client has exceeded their request allotment.
	RateLimitExceeded = "rate_limit_exceeded"
	// RequestFailed is returned when an outbound request failed.
	RequestFailed = "request_failed"
	// RequestTooLarge is returned when the client provided payload is larger than allowed for the particular resource.
	RequestTooLarge = "request_too_large"
	// Unauthorized is for unauthorized access.
	Unauthorized = "unauthorized"
	// Unexpected is returned when something went wrong.
	Unexpected = "unexpected"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

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

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

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

	// Cause is the original error
	Cause error `json:"-"`
}

Error represents a single error from API.

func New

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

New builds a new Error instance, building the message string along the way

func WithAccountNotFound

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

WithAccountNotFound for builds a new Error instance with AccountNotFound code

func WithBadNonce

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

WithBadNonce for builds a new Error instance with BadNonce code

func WithConflict

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

WithConflict for builds a new Error instance with Conflict code

func WithContentLengthRequired

func WithContentLengthRequired() *Error

WithContentLengthRequired for builds a new Error instance with ContentLengthRequired code

func WithFailedToReadRequestBody

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

WithFailedToReadRequestBody for builds a new Error instance with FailedToReadRequestBody code

func WithForbidden

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

WithForbidden for builds a new Error instance with Forbidden code

func WithInvalidContentType

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

WithInvalidContentType for builds a new Error instance with InvalidContentType code

func WithInvalidJSON

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

WithInvalidJSON for builds a new Error instance with InvalidJSON code

func WithInvalidParam

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

WithInvalidParam for builds a new Error instance with InvalidParam code

func WithInvalidRequest

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

WithInvalidRequest for builds a new Error instance with InvalidRequest code

func WithMalformed

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

WithMalformed for builds a new Error instance with Malformed code

func WithNotFound

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

WithNotFound for builds a new Error instance with NotFound code

func WithNotReady

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

WithNotReady for builds a new Error instance with NotReady code

func WithRateLimitExceeded

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

WithRateLimitExceeded for builds a new Error instance with RateLimitExceeded code

func WithRequestTooLarge

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

WithRequestTooLarge for builds a new Error instance with RequestTooLarge code

func WithUnauthorized

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

WithUnauthorized for builds a new Error instance with Unauthorized code

func WithUnexpected

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

WithUnexpected for builds a new Error instance with Unexpected code

func (*Error) Error

func (e *Error) Error() string

Error implements the standard error interface

func (*Error) WithCause

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

WithCause adds the cause error

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:"-"`

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

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

	Errors map[string]*Error `json:"errors,omitempty"`
}

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) Error

func (m *ManyError) Error() string

func (*ManyError) HasErrors

func (m *ManyError) HasErrors() bool

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

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