httperror

package
v0.7.23 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	DisplayMsg string `json:"display_message"`
	HTTPStatus int    `json:"status"`
	Err        error  `json:"-"`
}

Error enriches the original go error type with

DisplayMsg the human readable display message
HTTPStatus the HTTP status code
Err the internal error

func InternalServerError

func InternalServerError(err error) *Error

InternalServerError returns a internal server error message with code 500. Display message: "An internal server error occurred."

func New

func New(httpStatus int, displayMsg string, err error) *Error

New returns a new error

func NotFound

func NotFound(res string, err error) *Error

NotFound returns a not found message with code 404. The following display message is returned: "The [res] was not found."

func ParameterMissing

func ParameterMissing(param string, err error) *Error

ParameterMissing returns a parameter missing message with code 422. Display message: "The parameter [param] is invalid."

func PermissionDenied

func PermissionDenied(action, subject string, err error) *Error

PermissionDenied returns a permission denied message with code 403. The following display message is returned: "You are not allowed to [action] the [subject]."

func ValueRequired

func ValueRequired(param string) *Error

ValueRequired returns a value required message with code 422. Display message: "Please fill out the field [param]."

func ValueTooLong

func ValueTooLong(param string, nchars int) *Error

ValueTooLong returns the following display message with code 422. Display message: "The value of [param] is too long. Maximum [nchars] characters are allowed."

func (Error) Error

func (e Error) Error() string

func (*Error) Unwrap added in v0.7.19

func (e *Error) Unwrap() error

Jump to

Keyboard shortcuts

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