httperror

package
v0.0.0-...-53e80a7 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: AGPL-3.0 Imports: 3 Imported by: 0

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