httperrors

package
v3.22.2 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2024 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAccountIDParameter            = errors.New("the accountId parameter must be set")
	ErrAccountNameNotUnique          = errors.New("the account name must be unique for the budget")
	ErrCategoryNameNotUnique         = errors.New("the category name must be unique for the budget")
	ErrCleanupConfirmation           = errors.New("the confirmation for the cleanup API call was incorrect")
	ErrDatabaseClosed                = errors.New("there is a problem with the database connection, please try again later")
	ErrDatabaseReadOnly              = errors.New("the database is currently in read-only mode, please try again later")
	ErrEnvelopeNameNotUniqe          = errors.New("the envelope name must be unique for the category")
	ErrFileEmpty                     = errors.New("the file you uploaded is empty or invalid")
	ErrInvalidBody                   = errors.New("the body of your request contains invalid or un-parseable data. Please check and try again")
	ErrInvalidMonth                  = errors.New("could not parse the specified month, did you use YYYY-MM format?")
	ErrInvalidQueryString            = errors.New("the query string contains unparseable data. Please check the values")
	ErrInvalidUUID                   = errors.New("the specified resource ID is not a valid UUID")
	ErrMonthNotSetInQuery            = errors.New("the month query parameter must be set")
	ErrMultipleAllocations           = errors.New("you can not create multiple allocations for the same month")
	ErrNoFilePost                    = errors.New("you must send a file to this endpoint")
	ErrNoResource                    = errors.New("there is no resource for the ID you specified")
	ErrReferenceResourceDoesNotExist = errors.New("a resource you are referencing in another resource does not exist")
	ErrRequestBodyEmpty              = errors.New("the request body must not be empty")
	ErrSourceEqualsDestination       = errors.New("source and destination accounts for a transaction must be different")
)

Functions

func Handler

func Handler(c *gin.Context, err error)

Handler handles errors for fetching data from the database.

This function is deprecated. Use Parse and handle HTTP responses in the calling function.

func InvalidMonth

func InvalidMonth(c *gin.Context)

func InvalidQueryString

func InvalidQueryString(c *gin.Context)

func InvalidUUID

func InvalidUUID(c *gin.Context)

func New

func New(c *gin.Context, status int, msgAndArgs ...any)

Generate a struct containing the HTTP error on the fly.

Types

type Error added in v3.5.0

type Error struct {
	Err    error
	Status int // Used with http.StatusX for the corresponding HTTP status code
}

Error is used to return an error with the corresponding HTTP status code to a controller.

func DBError

func DBError(c *gin.Context, err error) Error

DBError returns an error message and status code appropriate to the error that has occurred.

func GenericDBError

func GenericDBError[T models.Model](r T, c *gin.Context, err error) Error

GenericDBError wraps DBError with a more specific error message for not found errors.

func Parse added in v3.5.0

func Parse(c *gin.Context, err error) Error

Parse parses an error and returns an appropriate Error struct.

If the error is not well known, it is logged and a generic message with the Request ID returned. This is done to prevent leaking sensitive data.

func (Error) Error added in v3.5.0

func (e Error) Error() string

Error returns the error as a string.

func (Error) Nil added in v3.5.0

func (e Error) Nil() bool

Nil checks if the ErrorStatus is the zero value.

type HTTPError

type HTTPError struct {
	Error string `json:"error" example:"An ID specified in the query string was not a valid UUID"`
}

Jump to

Keyboard shortcuts

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