httperrors

package
v3.2.3 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2023 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

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

Handler handles errors for fetching data from the database.

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 ErrorStatus

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

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

func DBError

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

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

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

func (ErrorStatus) Body

func (e ErrorStatus) Body() map[string]string

Body returns the the content of the HTTP response body for the error.

func (ErrorStatus) Error

func (e ErrorStatus) Error() string

Error returns the error as string.

func (ErrorStatus) Nil

func (e ErrorStatus) 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