errors

package
v0.0.0-...-5623d4f Latest Latest
Warning

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

Go to latest
Published: May 12, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrBadRequest         = "bad_request"
	ErrForbidden          = "forbidden"
	ErrInternalService    = "internal_service"
	ErrNotFound           = "not_found"
	ErrPreconditionFailed = "precondition_failed"
	ErrTimeout            = "timeout"
	ErrUnauthorized       = "unauthorized"
)

Generic error codes. Each of these has their own constructor for convenience. You can use any string as a code, just use the `New` method.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Code     string            `json:"code"`
	Message  string            `json:"message"`
	Metadata map[string]string `json:"metadata"`
}

Error is a custom error type that implements Go's error interface

func BadRequest

func BadRequest(format string, a ...interface{}) *Error

BadRequest creates a new error to represent an error caused by the client sending an invalid request. This is non-retryable unless the request is modified.

func Forbidden

func Forbidden(format string, a ...interface{}) *Error

Forbidden creates a new error representing a resource that cannot be accessed with the current authorisation credentials. The user may need authorising, or if authorised, may not be permitted to perform this action.

func InternalService

func InternalService(format string, a ...interface{}) *Error

InternalService creates a new error to represent an internal service error

func NotFound

func NotFound(format string, a ...interface{}) *Error

NotFound creates a new error representing a resource that cannot be found

func PreconditionFailed

func PreconditionFailed(format string, a ...interface{}) *Error

PreconditionFailed creates a new error indicating that one or more conditions given in the request evaluated to false when tested on the server

func Timeout

func Timeout(format string, a ...interface{}) *Error

Timeout creates a new error representing a timeout from client to server

func Unauthorized

func Unauthorized(format string, a ...interface{}) *Error

Unauthorized creates a new error indicating that authentication is required, but has either failed or not been provided.

func Wrap

func Wrap(err error, metadata map[string]string) *Error

func (*Error) Error

func (e *Error) Error() string

Error returns a string message of the error

func (*Error) GetMetadata

func (e *Error) GetMetadata() map[string]string

func (*Error) HTTPStatus

func (e *Error) HTTPStatus() int

HTTPStatus returns an appropriate HTTP status code to use when returning the error in a response

func (*Error) Matches

func (e *Error) Matches(match string) bool

Matches returns whether the string returned from error.Error() contains the given param string

Jump to

Keyboard shortcuts

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