httperrors

package
v2.12.2 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2023 License: AGPL-3.0 Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 added in v2.10.0

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 added in v2.10.0

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 added in v2.10.0

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 added in v2.10.0

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

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

func (ErrorStatus) Error added in v2.10.0

func (e ErrorStatus) Error() string

Error returns the error as string.

func (ErrorStatus) Nil added in v2.10.0

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 uint64"`
}

Jump to

Keyboard shortcuts

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