apierrors

package
v0.0.0-...-692641c Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2020 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// BadRequest return status 400 Bad Request for malformed request body.
	BadRequest = &ErrResponse{HTTPStatusCode: http.StatusBadRequest, StatusText: http.StatusText(http.StatusBadRequest)}
	// NotFound returns status 404 Not Found for invalid resource request.
	NotFound = &ErrResponse{HTTPStatusCode: http.StatusNotFound, StatusText: http.StatusText(http.StatusNotFound)}
	// Unauthorized returns 401 Unauthorized.
	Unauthorized = &ErrResponse{HTTPStatusCode: http.StatusUnauthorized, StatusText: http.StatusText(http.StatusUnauthorized)}
	// Forbidden returns status 403 Forbidden for unauthorized request.
	Forbidden = &ErrResponse{HTTPStatusCode: http.StatusForbidden, StatusText: http.StatusText(http.StatusForbidden)}
	// InternalServerError returns status 500 Internal Server Error.
	InternalServerError = &ErrResponse{HTTPStatusCode: http.StatusInternalServerError, StatusText: http.StatusText(http.StatusInternalServerError)}
)

Functions

func ErrBadRequest

func ErrBadRequest(err error) render.Renderer

ErrBadRequest returns status 400 bad request including errors message.

func ErrInternalError

func ErrInternalError(err error) render.Renderer

ErrInternalError renders status 500 Internal server error with custom errors message.

func ErrInvalidRequest

func ErrInvalidRequest(err error) render.Renderer

ErrInvalidRequest returns status 422 Unprocessable Entity including errors message.

func ErrNotFound

func ErrNotFound(err error) render.Renderer

ErrNotFound renders status 404 NotFound with custom errors message.

func ErrUnauthorized

func ErrUnauthorized(err error) render.Renderer

ErrUnauthorized renders status 401 Unauthorized with custom errors message.

func ErrValidation

func ErrValidation(err error, valErr validation.Errors) render.Renderer

ErrValidation returns status 422 Unprocessable Entity stating validation errors.

Types

type ErrResponse

type ErrResponse struct {
	Err            error `json:"-"` // low-level runtime errors
	HTTPStatusCode int   `json:"-"` // http response status code

	StatusText       string            `json:"status"`                      // user-level status message
	AppCode          string            `json:"code,omitempty"`              // application-specific errors code
	ErrorText        string            `json:"errors,omitempty"`            // application-level errors message, for debugging
	ValidationErrors validation.Errors `json:"validation_errors,omitempty"` // user level model validation errors
}

ErrResponse renderer type for handling all sorts of errors.

func (*ErrResponse) Render

func (e *ErrResponse) Render(w http.ResponseWriter, r *http.Request) error

Render sets the application-specific errors code in AppCode.

Jump to

Keyboard shortcuts

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