httperror

package
v0.0.0-...-65d01b3 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2024 License: AGPL-3.0 Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(statusCode int, errorsMap *map[string]string) error

New creates a new HTTPError instance with a multi-field errors.

func NewForBadRequest

func NewForBadRequest(err *map[string]string) error

NewForBadRequest create a new HTTPError instance pertaining to 403 bad requests with the multi-errors. This is a convinience constructor.

func NewForBadRequestWithSingleField

func NewForBadRequestWithSingleField(field string, message string) error

NewForBadRequestWithSingleField create a new HTTPError instance pertaining to 403 bad requests for a single field. This is a convinience constructor.

func NewForForbiddenWithSingleField

func NewForForbiddenWithSingleField(field string, message string) error

NewForForbiddenWithSingleField create a new HTTPError instance pertaining to 403 bad requests for a single field. This is a convinience constructor.

func NewForGoneWithSingleField

func NewForGoneWithSingleField(field string, message string) error

NewForGoneWithSingleField create a new HTTPError instance pertaining to 410 gone for a single field. This is a convinience constructor.

func NewForLockedWithSingleField

func NewForLockedWithSingleField(field string, message string) error

NewForLockedWithSingleField create a new HTTPError instance pertaining to 424 locked for a single field. This is a convinience constructor.

func NewForNotFoundWithSingleField

func NewForNotFoundWithSingleField(field string, message string) error

NewForNotFoundWithSingleField create a new HTTPError instance pertaining to 404 not found for a single field. This is a convinience constructor.

func NewForServiceUnavailableWithSingleField

func NewForServiceUnavailableWithSingleField(field string, message string) error

NewForServiceUnavailableWithSingleField create a new HTTPError instance pertaining service unavailable for a single field. This is a convinience constructor.

func NewForSingleField

func NewForSingleField(statusCode int, field string, message string) error

NewForSingleField create a new HTTPError instance for a single field. This is a convinience constructor.

func NewForUnauthorizedWithSingleField

func NewForUnauthorizedWithSingleField(field string, message string) error

NewForUnauthorizedWithSingleField create a new HTTPError instance pertaining to 401 unauthorized for a single field. This is a convinience constructor.

func ResponseError

func ResponseError(rw http.ResponseWriter, err error)

ResponseError function returns the HTTP error response based on the httpcode used.

Types

type HTTPError

type HTTPError struct {
	Code   int                `json:"-"` // HTTP Status code. We use `-` to skip json marshaling.
	Errors *map[string]string `json:"-"` // The original error. Same reason as above.
}

HTTPError represents an http error that occurred while handling a request

func (HTTPError) Error

func (err HTTPError) Error() string

Error function used to implement the `error` interface for returning errors.

Jump to

Keyboard shortcuts

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