errutils

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2022 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPError

type HTTPError struct {
	Status int    `json:"-"`
	Code   string `json:"code"`
	Reason string `json:"reason"`
}

HTTPError is a custom error type that implements the error interface.

func BadRequest

func BadRequest() *HTTPError

BadRequest is for logically incorrect requests.

func Conflict

func Conflict() *HTTPError

Conflict is for requests that attempt paradoxical operations, such as re-creating the same resource.

func Forbidden

func Forbidden() *HTTPError

Forbidden is for requests that do not have enough authority to execute the operation.

func InternalServerError

func InternalServerError() *HTTPError

InternalServerError is for requests that cause an unexpected misbehaviour.

func NotFound

func NotFound() *HTTPError

NotFound is for requests that try to access a non-existent resource.

func PaymentRequired

func PaymentRequired() *HTTPError

PaymentRequired is for requests that require payment completion.

func PreconditionFailed

func PreconditionFailed() *HTTPError

PreconditionFailed is for requests that do not satisfy pre-business layers of the application.

func RequestTimeout

func RequestTimeout() *HTTPError

RequestTimeout is for requests that take longer than a certain time limit to execute.

func ServiceUnavailable

func ServiceUnavailable() *HTTPError

ServiceUnavailable is returned when the system is not available enough to serve the request.

func ToHTTPError

func ToHTTPError(err interface{}) *HTTPError

ToHTTPError converts any value to an appropriate HTTPError.

func Unauthorized

func Unauthorized() *HTTPError

Unauthorized is for requests with invalid credentials.

func (*HTTPError) Error

func (h *HTTPError) Error() string

Error provides the reason behind the error, which is usually human-readable. If the reason is absent, it provides the error code instead.

func (*HTTPError) WithReasonErr

func (h *HTTPError) WithReasonErr(reason error) *HTTPError

WithReasonErr is a chainable method to set the reason of the HTTPError.

This accepts the reason as an error.

func (*HTTPError) WithReasonStr

func (h *HTTPError) WithReasonStr(reason string) *HTTPError

WithReasonStr is a chainable method to set the reason of the HTTPError.

This accepts the reason as a string.

Jump to

Keyboard shortcuts

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