...

Package errors

import "github.com/go-openapi/errors"
Overview
Index

Overview ▾

Package errors provides an Error interface and several concrete types implementing this interface to manage API errors and JSON-schema validation errors.

A middleware handler ServeError() is provided to serve the errors types it defines.

It is used throughout the various go-openapi toolkit libraries (https://github.com/go-openapi).

Index ▾

Constants
Variables
func ServeError(rw http.ResponseWriter, r *http.Request, err error)
type APIVerificationFailed
    func (v *APIVerificationFailed) Error() string
type CompositeError
    func CompositeValidationError(errors ...error) *CompositeError
    func (c *CompositeError) Code() int32
    func (c *CompositeError) Error() string
    func (c CompositeError) MarshalJSON() ([]byte, error)
    func (c *CompositeError) Unwrap() []error
    func (c *CompositeError) ValidateName(name string) *CompositeError
type Error
    func MethodNotAllowed(requested string, allow []string) Error
    func New(code int32, message string, args ...interface{}) Error
    func NotFound(message string, args ...interface{}) Error
    func NotImplemented(message string) Error
    func Unauthenticated(scheme string) Error
type MethodNotAllowedError
    func (m *MethodNotAllowedError) Code() int32
    func (m *MethodNotAllowedError) Error() string
    func (m MethodNotAllowedError) MarshalJSON() ([]byte, error)
type ParseError
    func NewParseError(name, in, value string, reason error) *ParseError
    func (e *ParseError) Code() int32
    func (e *ParseError) Error() string
    func (e ParseError) MarshalJSON() ([]byte, error)
type Validation
    func AdditionalItemsNotAllowed(name, in string) *Validation
    func DuplicateItems(name, in string) *Validation
    func EnumFail(name, in string, value interface{}, values []interface{}) *Validation
    func ExceedsMaximum(name, in string, max float64, exclusive bool, value interface{}) *Validation
    func ExceedsMaximumInt(name, in string, max int64, exclusive bool, value interface{}) *Validation
    func ExceedsMaximumUint(name, in string, max uint64, exclusive bool, value interface{}) *Validation
    func ExceedsMinimum(name, in string, min float64, exclusive bool, value interface{}) *Validation
    func ExceedsMinimumInt(name, in string, min int64, exclusive bool, value interface{}) *Validation
    func ExceedsMinimumUint(name, in string, min uint64, exclusive bool, value interface{}) *Validation
    func FailedAllPatternProperties(name, in, key string) *Validation
    func FailedPattern(name, in, pattern string, value interface{}) *Validation
    func InvalidCollectionFormat(name, in, format string) *Validation
    func InvalidContentType(value string, allowed []string) *Validation
    func InvalidResponseFormat(value string, allowed []string) *Validation
    func InvalidType(name, in, typeName string, value interface{}) *Validation
    func InvalidTypeName(typeName string) *Validation
    func MultipleOfMustBePositive(name, in string, factor interface{}) *Validation
    func NotMultipleOf(name, in string, multiple, value interface{}) *Validation
    func PropertyNotAllowed(name, in, key string) *Validation
    func ReadOnly(name, in string, value interface{}) *Validation
    func Required(name, in string, value interface{}) *Validation
    func TooFewItems(name, in string, min int64, value interface{}) *Validation
    func TooFewProperties(name, in string, n int64) *Validation
    func TooLong(name, in string, max int64, value interface{}) *Validation
    func TooManyItems(name, in string, max int64, value interface{}) *Validation
    func TooManyProperties(name, in string, n int64) *Validation
    func TooShort(name, in string, min int64, value interface{}) *Validation
    func (e *Validation) Code() int32
    func (e *Validation) Error() string
    func (e Validation) MarshalJSON() ([]byte, error)
    func (e *Validation) ValidateName(name string) *Validation

Package files

api.go auth.go doc.go headers.go middleware.go parsing.go schema.go

Constants

All code responses can be used to differentiate errors for different handling by the consuming program

const (
    // CompositeErrorCode remains 422 for backwards-compatibility
    // and to separate it from validation errors with cause
    CompositeErrorCode = 422
    // InvalidTypeCode is used for any subclass of invalid types
    InvalidTypeCode = 600 + iota
    RequiredFailCode
    TooLongFailCode
    TooShortFailCode
    PatternFailCode
    EnumFailCode
    MultipleOfFailCode
    MaxFailCode
    MinFailCode
    UniqueFailCode
    MaxItemsFailCode
    MinItemsFailCode
    NoAdditionalItemsCode
    TooFewPropertiesCode
    TooManyPropertiesCode
    UnallowedPropertyCode
    FailedAllPatternPropsCode
    MultipleOfMustBePositiveCode
    ReadOnlyFailCode
)

Variables

DefaultHTTPCode is used when the error Code cannot be used as an HTTP code.

var DefaultHTTPCode = http.StatusUnprocessableEntity

func ServeError

func ServeError(rw http.ResponseWriter, r *http.Request, err error)

ServeError implements the http error handler interface

type APIVerificationFailed

APIVerificationFailed is an error that contains all the missing info for a mismatched section between the api registrations and the api spec

type APIVerificationFailed struct {
    Section              string   `json:"section,omitempty"`
    MissingSpecification []string `json:"missingSpecification,omitempty"`
    MissingRegistration  []string `json:"missingRegistration,omitempty"`
}

func (*APIVerificationFailed) Error

func (v *APIVerificationFailed) Error() string

type CompositeError

CompositeError is an error that groups several errors together

type CompositeError struct {
    Errors []error
    // contains filtered or unexported fields
}

func CompositeValidationError

func CompositeValidationError(errors ...error) *CompositeError

CompositeValidationError an error to wrap a bunch of other errors

func (*CompositeError) Code

func (c *CompositeError) Code() int32

Code for this error

func (*CompositeError) Error

func (c *CompositeError) Error() string

func (CompositeError) MarshalJSON

func (c CompositeError) MarshalJSON() ([]byte, error)

MarshalJSON implements the JSON encoding interface

func (*CompositeError) Unwrap

func (c *CompositeError) Unwrap() []error

func (*CompositeError) ValidateName

func (c *CompositeError) ValidateName(name string) *CompositeError

ValidateName recursively sets the name for all validations or updates them for nested properties

type Error

Error represents a error interface all swagger framework errors implement

type Error interface {
    error
    Code() int32
}

func MethodNotAllowed

func MethodNotAllowed(requested string, allow []string) Error

MethodNotAllowed creates a new method not allowed error

func New

func New(code int32, message string, args ...interface{}) Error

New creates a new API error with a code and a message

func NotFound

func NotFound(message string, args ...interface{}) Error

NotFound creates a new not found error

func NotImplemented

func NotImplemented(message string) Error

NotImplemented creates a new not implemented error

func Unauthenticated

func Unauthenticated(scheme string) Error

Unauthenticated returns an unauthenticated error

type MethodNotAllowedError

MethodNotAllowedError represents an error for when the path matches but the method doesn't

type MethodNotAllowedError struct {
    Allowed []string
    // contains filtered or unexported fields
}

func (*MethodNotAllowedError) Code

func (m *MethodNotAllowedError) Code() int32

Code the error code

func (*MethodNotAllowedError) Error

func (m *MethodNotAllowedError) Error() string

func (MethodNotAllowedError) MarshalJSON

func (m MethodNotAllowedError) MarshalJSON() ([]byte, error)

MarshalJSON implements the JSON encoding interface

type ParseError

ParseError represents a parsing error

type ParseError struct {
    Name   string
    In     string
    Value  string
    Reason error
    // contains filtered or unexported fields
}

func NewParseError

func NewParseError(name, in, value string, reason error) *ParseError

NewParseError creates a new parse error

func (*ParseError) Code

func (e *ParseError) Code() int32

Code returns the http status code for this error

func (*ParseError) Error

func (e *ParseError) Error() string

func (ParseError) MarshalJSON

func (e ParseError) MarshalJSON() ([]byte, error)

MarshalJSON implements the JSON encoding interface

type Validation

Validation represents a failure of a precondition

type Validation struct {
    Name  string
    In    string
    Value interface{}

    Values []interface{}
    // contains filtered or unexported fields
}

func AdditionalItemsNotAllowed

func AdditionalItemsNotAllowed(name, in string) *Validation

AdditionalItemsNotAllowed an error for invalid additional items

func DuplicateItems

func DuplicateItems(name, in string) *Validation

DuplicateItems error for when an array contains duplicates

func EnumFail

func EnumFail(name, in string, value interface{}, values []interface{}) *Validation

EnumFail error for when an enum validation fails

func ExceedsMaximum

func ExceedsMaximum(name, in string, max float64, exclusive bool, value interface{}) *Validation

ExceedsMaximum error for when maximum validation fails

func ExceedsMaximumInt

func ExceedsMaximumInt(name, in string, max int64, exclusive bool, value interface{}) *Validation

ExceedsMaximumInt error for when maximum validation fails

func ExceedsMaximumUint

func ExceedsMaximumUint(name, in string, max uint64, exclusive bool, value interface{}) *Validation

ExceedsMaximumUint error for when maximum validation fails

func ExceedsMinimum

func ExceedsMinimum(name, in string, min float64, exclusive bool, value interface{}) *Validation

ExceedsMinimum error for when minimum validation fails

func ExceedsMinimumInt

func ExceedsMinimumInt(name, in string, min int64, exclusive bool, value interface{}) *Validation

ExceedsMinimumInt error for when minimum validation fails

func ExceedsMinimumUint

func ExceedsMinimumUint(name, in string, min uint64, exclusive bool, value interface{}) *Validation

ExceedsMinimumUint error for when minimum validation fails

func FailedAllPatternProperties

func FailedAllPatternProperties(name, in, key string) *Validation

FailedAllPatternProperties an error for when the property doesn't match a pattern

func FailedPattern

func FailedPattern(name, in, pattern string, value interface{}) *Validation

FailedPattern error for when a string fails a regex pattern match the pattern that is returned is the ECMA syntax version of the pattern not the golang version.

func InvalidCollectionFormat

func InvalidCollectionFormat(name, in, format string) *Validation

InvalidCollectionFormat another flavor of invalid type error

func InvalidContentType

func InvalidContentType(value string, allowed []string) *Validation

InvalidContentType error for an invalid content type

func InvalidResponseFormat

func InvalidResponseFormat(value string, allowed []string) *Validation

InvalidResponseFormat error for an unacceptable response format request

func InvalidType

func InvalidType(name, in, typeName string, value interface{}) *Validation

InvalidType creates an error for when the type is invalid

func InvalidTypeName

func InvalidTypeName(typeName string) *Validation

InvalidTypeName an error for when the type is invalid

func MultipleOfMustBePositive

func MultipleOfMustBePositive(name, in string, factor interface{}) *Validation

MultipleOfMustBePositive error for when a multipleOf factor is negative

func NotMultipleOf

func NotMultipleOf(name, in string, multiple, value interface{}) *Validation

NotMultipleOf error for when multiple of validation fails

func PropertyNotAllowed

func PropertyNotAllowed(name, in, key string) *Validation

PropertyNotAllowed an error for when the property doesn't match a pattern

func ReadOnly

func ReadOnly(name, in string, value interface{}) *Validation

ReadOnly error for when a value is present in request

func Required

func Required(name, in string, value interface{}) *Validation

Required error for when a value is missing

func TooFewItems

func TooFewItems(name, in string, min int64, value interface{}) *Validation

TooFewItems error for when an array contains too few items

func TooFewProperties

func TooFewProperties(name, in string, n int64) *Validation

TooFewProperties an error for an object with too few properties

func TooLong

func TooLong(name, in string, max int64, value interface{}) *Validation

TooLong error for when a string is too long

func TooManyItems

func TooManyItems(name, in string, max int64, value interface{}) *Validation

TooManyItems error for when an array contains too many items

func TooManyProperties

func TooManyProperties(name, in string, n int64) *Validation

TooManyProperties an error for an object with too many properties

func TooShort

func TooShort(name, in string, min int64, value interface{}) *Validation

TooShort error for when a string is too short

func (*Validation) Code

func (e *Validation) Code() int32

Code the error code

func (*Validation) Error

func (e *Validation) Error() string

func (Validation) MarshalJSON

func (e Validation) MarshalJSON() ([]byte, error)

MarshalJSON implements the JSON encoding interface

func (*Validation) ValidateName

func (e *Validation) ValidateName(name string) *Validation

ValidateName sets the name for a validation or updates it for a nested property