fail

package module
v0.0.0-...-579e16d Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2018 License: Apache-2.0 Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnspecified is an error with no cause or reason.
	ErrUnspecified = fmt.Errorf("unspecified error")
)

Functions

func BadRequest

func BadRequest(m string, fields ...string) error

BadRequest is a convenience function to return a BadRequest fail.

func Because

func Because(err error) error

Because returns the previous error if it's a fail.

func Conflict

func Conflict(m string, fields ...string) error

Conflict is a convenience function to return a Conflict fail.

func ErrorJSON

func ErrorJSON(w http.ResponseWriter, err error)

ErrorJSON complements `http.Error` by sending a fail response.

func ErrorPlain

func ErrorPlain(w http.ResponseWriter, err error)

ErrorPlain complements `http.Error` by sending a fail response.

func FailedDependency

func FailedDependency(m string, fields ...string) error

FailedDependency is a convenience function to return a FailedDependency fail.

func Forbidden

func Forbidden(m string, fields ...string) error

Forbidden is a convenience function to return a Forbidden fail.

func IsBadRequest

func IsBadRequest(err error) bool

IsBadRequest returns true if fail is a BadRequest fail, false otherwise.

func IsConflict

func IsConflict(err error) bool

IsConflict returns true if fail is a Conflict fail, false otherwise.

func IsFailedDependency

func IsFailedDependency(err error) bool

IsFailedDependency returns true if fail is a FailedDependency fail, false otherwise.

func IsForbidden

func IsForbidden(err error) bool

IsForbidden returns true if fail is a Forbidden fail, false otherwise.

func IsLocked

func IsLocked(err error) bool

IsLocked returns true if fail is a Locked fail, false otherwise.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound returns true if fail is a NotFound fail, false otherwise.

func IsPreconditionFailed

func IsPreconditionFailed(err error) bool

IsPreconditionFailed returns true if fail is a PreconditionFailed fail, false otherwise.

func IsPreconditionRequired

func IsPreconditionRequired(err error) bool

IsPreconditionRequired returns true if fail is a PreconditionRequired fail, false otherwise.

func IsUnauthorized

func IsUnauthorized(err error) bool

IsUnauthorized returns true if fail is a Unauthorized fail, false otherwise.

func IsUnknown

func IsUnknown(err error) bool

IsUnknown returns true if err is not handled as a fail, false otheriwse.

func IsUnprocessableEntity

func IsUnprocessableEntity(err error) bool

IsUnprocessableEntity returns true if fail is a UnprocessableEntity fail, false otherwise.

func Locked

func Locked(m string, fields ...string) error

Locked is a convenience function to return a Locked fail.

func NotFound

func NotFound(m string, fields ...string) error

NotFound is a convenience function to return a Not Found fail.

func PreconditionFailed

func PreconditionFailed(m string, fields ...string) error

PreconditionFailed is a convenience function to return a PreconditionFailed fail.

func PreconditionRequired

func PreconditionRequired(m string, fields ...string) error

PreconditionRequired is a convenience function to return a PreconditionRequired fail.

func Say

func Say(err error) (int, string)

Say returns the HTTP status and message response of a fail.

func Unauthorized

func Unauthorized(m string, fields ...string) error

Unauthorized is a convenience function to return an Unauthorized fail.

func Unexpected

func Unexpected() error

Unexpected is a convenience function to return an Unexpected fail.

func UnprocessableEntity

func UnprocessableEntity(m string, fields ...string) error

UnprocessableEntity is a convenience function to return a UnprocessableEntity fail.

Types

type Fail

type Fail struct {
	Status  int      `json:"status"`
	Message string   `json:"message"`
	Details []string `json:"details,omitempty"`
	// contains filtered or unexported fields
}

Fail is an error that can be used in an HTTP response.

func Cause

func Cause(prev error) *Fail

Cause wraps an error into a fail so it can be used in a response.

func (*Fail) BadRequest

func (f *Fail) BadRequest(m string, details ...string) error

BadRequest changes the error to a "Bad Request" fail.

func (*Fail) Caller

func (f *Fail) Caller(skip int)

Caller finds the file and line where the failure happened.

func (*Fail) Conflict

func (f *Fail) Conflict(m string, details ...string) error

Conflict changes the error to a "Conflict" fail.

func (*Fail) Error

func (f *Fail) Error() string

Error implements the error interface.

func (*Fail) FailedDependency

func (f *Fail) FailedDependency(m string, details ...string) error

FailedDependency changes the error to a "Failed Dependency" fail.

func (*Fail) Forbidden

func (f *Fail) Forbidden(m string, details ...string) error

Forbidden changes an error to a "Forbidden" fail.

func (*Fail) Format

func (f *Fail) Format(s fmt.State, c rune)

Format implements the fmt.Formatter interface.

func (*Fail) Locked

func (f *Fail) Locked(m string, details ...string) error

Locked changes the error to a "Locked" fail.

func (*Fail) NotFound

func (f *Fail) NotFound(m string, details ...string) error

NotFound changes the error to an "Not Found" fail.

func (*Fail) PreconditionFailed

func (f *Fail) PreconditionFailed(m string, details ...string) error

PreconditionFailed changes the error to a "Precondition Failed" fail.

func (*Fail) PreconditionRequired

func (f *Fail) PreconditionRequired(m string, details ...string) error

PreconditionRequired changes the error to a "Precondition Required" fail.

func (*Fail) String

func (f *Fail) String() string

String implements the fmt.Stringer interface.

func (*Fail) Unauthorized

func (f *Fail) Unauthorized(m string, details ...string) error

Unauthorized changes the error to an "Unauthorized" fail.

func (*Fail) Unexpected

func (f *Fail) Unexpected() error

Unexpected morphs the error into an "Internal Server Error" fail.

func (*Fail) UnprocessableEntity

func (f *Fail) UnprocessableEntity(m string, details ...string) error

UnprocessableEntity changes the error to a "Unprocessable Entity" fail.

Jump to

Keyboard shortcuts

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