errors

package
v0.0.0-...-5ae7496 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadMessages

func LoadMessages(file string) error

LoadMessages reads a YAML file containing error templates.

Types

type APIError

type APIError struct {
	// Status represents the HTTP status code
	Status int `json:"-"`
	// ErrorCode is the code uniquely identifying an error
	ErrorCode string `json:"error_code"`
	// Message is the error message that may be displayed to end users
	Message string `json:"message"`
	// DeveloperMessage is the error message that is mainly meant for developers
	DeveloperMessage string `json:"developer_message,omitempty"`
	// Details specifies the additional error information
	Details interface{} `json:"details,omitempty"`
}

APIError represents an error that can be sent in an error response.

func InternalServerError

func InternalServerError(err error) *APIError

InternalServerError creates a new API error representing an internal server error (HTTP 500)

func InvalidData

func InvalidData(errs validation.Errors) *APIError

InvalidData converts a data validation error into an API error (HTTP 400)

func NewHTTPError

func NewHTTPError(status int, code string, params Params) *APIError

NewHTTPError creates a new APIError with the given HTTP status code, error code, and parameters for replacing placeholders in the error template. The param can be nil, indicating there is no need for placeholder replacement.

func NotFound

func NotFound(resource string) *APIError

NotFound creates a new API error representing a resource-not-found error (HTTP 404)

func Unauthorized

func Unauthorized(err string) *APIError

Unauthorized creates a new API error representing an authentication failure (HTTP 401)

func (APIError) Error

func (e APIError) Error() string

Error returns the error message.

func (APIError) StatusCode

func (e APIError) StatusCode() int

StatusCode returns the HTTP status code.

type Params

type Params map[string]interface{}

Params is used to replace placeholders in an error template with the corresponding values.

Jump to

Keyboard shortcuts

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