httperror

package
v0.7.9 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2019 License: MIT Imports: 2 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equals

func Equals(a error, b error) bool

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 description for the displaying message HTTPStatus the HTTP status code Err the internal error it should not be shown to the user

func InternalServerError

func InternalServerError(err error) *Error

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

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

Jump to

Keyboard shortcuts

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