errors

package
v3.7.1 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPermission is the standard "Permission Denied" error
	// nolint: stylecheck // this a special error that is displayed to the user as it is.
	ErrPermission = errors.New("You don't have required permission to perform this action")
	// ErrAuthorization is the standard "Unauthorized" error
	// nolint: stylecheck // this a special error that is displayed to the user as it is.
	ErrAuthorization = errors.New("User is unauthorized, make sure you've logged in")
	// ErrInternal is the standard "Internal Server" error
	// nolint: stylecheck // this a special error that is displayed to the user as it is.
	ErrInternal = errors.New("Internal server error, please try again later")
	// ErrInvalidParameters is the standard "Bad Request" error
	// nolint: stylecheck // this a special error that is displayed to the user as it is.
	ErrInvalidParameters = errors.New("Some of the request parameters are not correct")
	// ErrUnmarshalling is the JSON deserialization error
	// nolint: stylecheck // this a special error that is displayed to the user as it is.
	ErrUnmarshalling = errors.New("Failed to read JSON from the request body")
	// ErrForm is the form parsing error
	// nolint: stylecheck // this a special error that is displayed to the user as it is.
	ErrForm = errors.New("Failed to parse the submitted form")
	// ErrNotFound is the standard entity not found error
	// nolint: stylecheck // this a special error that is displayed to the user as it is.
	ErrNotFound = errors.New("The requested object was not found")
	// ErrNotImplemented is intended to be used when stubbing new endpoints
	// nolint: stylecheck // this a special error that is displayed to the user as it is.
	ErrNotImplemented = errors.New("Method is not implemented")
	// ErrUnsupportedMediaType is intended to be used for endpoints that accepts multiple
	// media types and need to return the standard "415 Unsupported Media Type" response
	// nolint: stylecheck // this a special error that is displayed to the user as it is.
	ErrUnsupportedMediaType = errors.New("Unsupported Media Type")
)

Functions

func AsUserError added in v3.2.0

func AsUserError(err error) error

AsUserError wraps the error as a UserError type, this allows automatic handling by the BaseHandler

Types

type APIErrorMessenger added in v3.2.0

type APIErrorMessenger interface {
	GetType() ErrorType
	GetMessage() string
	// Scrubbed returns a copy of the instance with the message
	// replaced the cleaned value
	Scrubbed(string) APIErrorMessenger
}

APIErrorMessenger represents an error message

type ErrorResponse added in v3.2.0

type ErrorResponse struct {
	// Errors is a list of errors
	Errors []APIErrorMessenger `json:"errors"`
}

ErrorResponse is a generic API error response body

func ValidationErrorsToFieldErrorResponse

func ValidationErrorsToFieldErrorResponse(errs ValidationErrors) (resp ErrorResponse)

ValidationErrorsToFieldErrorResponse converts validation errors to the format that is served by HTTP handlers

type ErrorType

type ErrorType string

ErrorType : The type of the error response

const (
	// GeneralErrorType is a generic error type
	GeneralErrorType ErrorType = "GeneralError"
	// FieldErrorType is a field validation error type
	FieldErrorType ErrorType = "FieldError"
)

type FieldError

type FieldError struct {
	GeneralError
	// Key of the validated field
	Key string `json:"key"`
}

FieldError represents a validation error

func (FieldError) GetMessage added in v3.2.0

func (e FieldError) GetMessage() string

func (FieldError) GetType added in v3.2.0

func (e FieldError) GetType() ErrorType

func (FieldError) Scrubbed added in v3.2.0

func (e FieldError) Scrubbed(_ string) APIErrorMessenger

Scrubbed implemented the APIErrorMessanger, the scrubbing is a noop because FieldError is safe for users by default.

type FieldErrorResponse deprecated

type FieldErrorResponse struct {
	// Errors is a list of errors
	Errors []FieldError `json:"errors"`
}

FieldErrorResponse - Error message that contains detailed information about certain parameters being incorrect

Deprecated: replaced with the more generic ErrorResponse

type GeneralError

type GeneralError struct {
	// Type of the error
	Type ErrorType `json:"type"`
	// Message of the validation error
	Message string `json:"message"`
}

GeneralError represents a system error exposed to the user

func (GeneralError) GetMessage added in v3.2.0

func (e GeneralError) GetMessage() string

func (GeneralError) GetType added in v3.2.0

func (e GeneralError) GetType() ErrorType

func (GeneralError) Scrubbed added in v3.2.0

func (e GeneralError) Scrubbed(message string) APIErrorMessenger

Scrubbed implemented the APIErrorMessanger, the scrubbing is replaces the message with the given message value.

type GeneralErrorResponse deprecated

type GeneralErrorResponse struct {
	// Errors is a list of errors
	Errors []GeneralError `json:"errors"`
}

GeneralErrorResponse - General error response that usually has a very generic message

Deprecated: replaced with the more generic ErrorResponse

type UserError added in v3.2.0

type UserError struct {
	// contains filtered or unexported fields
}

UserError is an error wrapper that represents a GeneralError caused by some user data or request. The error message is considered safe to show to end users. The HTTP handler can recognize this error type and automatically parse it into a 400 error code.

func (UserError) Error added in v3.2.0

func (e UserError) Error() string

Error implements the error interface

func (UserError) Unwrap added in v3.2.0

func (e UserError) Unwrap() error

Unwrap implements the error wrapping interface to expose the source error

type ValidationErrors

type ValidationErrors = validation.Errors

ValidationErrors contains errors organized by validated fields for now it's just an alias to the validation library we use

Jump to

Keyboard shortcuts

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