errors

package
v1.12.2 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const HeaderErrorCode = "Couper-Error"
View Source
const Wildcard = "*"

Variables

View Source
var (
	AccessControl    = &Error{synopsis: "access control error", kinds: []string{"access_control"}, httpStatus: http.StatusForbidden}
	Backend          = &Error{synopsis: "backend error", Contexts: []string{"api", "endpoint"}, kinds: []string{"backend"}, httpStatus: http.StatusBadGateway}
	ClientRequest    = &Error{synopsis: "client request error", httpStatus: http.StatusBadRequest}
	Endpoint         = &Error{synopsis: "endpoint error", Contexts: []string{"endpoint"}, kinds: []string{"endpoint"}, httpStatus: http.StatusBadGateway}
	Evaluation       = &Error{synopsis: "expression evaluation error", kinds: []string{"evaluation"}, httpStatus: http.StatusInternalServerError}
	Configuration    = &Error{synopsis: "configuration error", kinds: []string{"configuration"}, httpStatus: http.StatusInternalServerError}
	MethodNotAllowed = &Error{synopsis: "method not allowed error", httpStatus: http.StatusMethodNotAllowed}
	Proxy            = &Error{synopsis: "proxy error", httpStatus: http.StatusBadGateway}
	Request          = &Error{synopsis: "request error", httpStatus: http.StatusBadGateway}
	RouteNotFound    = &Error{synopsis: "route not found error", httpStatus: http.StatusNotFound}
	Server           = &Error{synopsis: "internal server error", httpStatus: http.StatusInternalServerError}
	ServerShutdown   = &Error{synopsis: "server shutdown error", httpStatus: http.StatusInternalServerError}
)
View Source
var (
	BasicAuth                    = Definitions[1]
	BasicAuthCredentialsMissing  = Definitions[2]
	Jwt                          = Definitions[3]
	JwtTokenExpired              = Definitions[4]
	JwtTokenInvalid              = Definitions[5]
	JwtTokenMissing              = Definitions[6]
	Oauth2                       = Definitions[7]
	Saml2                        = Definitions[8]
	Saml                         = Definitions[9]
	InsufficientPermissions      = Definitions[10]
	BackendOpenapiValidation     = Definitions[12]
	BetaBackendRateLimitExceeded = Definitions[13]
	BackendTimeout               = Definitions[14]
	BetaBackendTokenRequest      = Definitions[15]
	BackendUnhealthy             = Definitions[16]
	Sequence                     = Definitions[18]
	UnexpectedStatus             = Definitions[19]
)
View Source
var Definitions = []*Error{
	AccessControl,

	AccessControl.Kind("basic_auth").Status(http.StatusUnauthorized),
	AccessControl.Kind("basic_auth").Kind("basic_auth_credentials_missing").Status(http.StatusUnauthorized),

	AccessControl.Kind("jwt").Status(http.StatusUnauthorized),
	AccessControl.Kind("jwt").Kind("jwt_token_expired").Status(http.StatusUnauthorized),
	AccessControl.Kind("jwt").Kind("jwt_token_invalid").Status(http.StatusUnauthorized),
	AccessControl.Kind("jwt").Kind("jwt_token_missing").Status(http.StatusUnauthorized),

	AccessControl.Kind("oauth2"),

	AccessControl.Kind("saml2"),
	AccessControl.Kind("saml2").Kind("saml"),

	AccessControl.Kind("insufficient_permissions").Context("api").Context("endpoint"),

	Backend,
	Backend.Kind("backend_openapi_validation").Status(http.StatusBadRequest),
	Backend.Kind("beta_backend_rate_limit_exceeded").Status(http.StatusTooManyRequests),
	Backend.Kind("backend_timeout").Status(http.StatusGatewayTimeout),
	Backend.Kind("beta_backend_token_request"),
	Backend.Kind("backend_unhealthy"),

	Endpoint,
	Endpoint.Kind("sequence"),
	Endpoint.Kind("unexpected_status"),
}

Definitions holds all implemented ones. The name must match the structs snake-name for fallback purposes. See TypeToSnake usage and reference.

View Source
var SuperTypesMapsByContext = map[string]map[string][]string{"api": map[string][]string{"*": []string{"insufficient_permissions", "backend_openapi_validation", "beta_backend_rate_limit_exceeded", "backend_timeout", "beta_backend_token_request", "backend_unhealthy"}, "access_control": []string{"insufficient_permissions"}, "backend": []string{"backend_openapi_validation", "beta_backend_rate_limit_exceeded", "backend_timeout", "beta_backend_token_request", "backend_unhealthy"}}, "endpoint": map[string][]string{"*": []string{"insufficient_permissions", "backend_openapi_validation", "beta_backend_rate_limit_exceeded", "backend_timeout", "beta_backend_token_request", "backend_unhealthy", "sequence", "unexpected_status"}, "access_control": []string{"insufficient_permissions"}, "backend": []string{"backend_openapi_validation", "beta_backend_rate_limit_exceeded", "backend_timeout", "beta_backend_token_request", "backend_unhealthy"}, "endpoint": []string{"sequence", "unexpected_status"}}}

SuperTypesMapsByContext holds maps for error super-types to sub-types by a given context block type (e.g. api or endpoint).

Functions

func AppendMsg

func AppendMsg(target string, messages ...string) string

AppendMsg chains the given strings with ": " as separator.

func Equals

func Equals(a, b error) bool

Equals returns true if the base type and kinds are equal.

func IsKnown

func IsKnown(errorType string) bool

IsKnown tells the configuration callee if Couper has a defined error type with the given name.

func SetLogger

func SetLogger(log *logrus.Entry)

SetLogger updates the default templates with the configured "daemon" logger.

func SnakeToCamel

func SnakeToCamel(str string) string

func TypeToSnake

func TypeToSnake(t interface{}) string

Types

type Error

type Error struct {
	Contexts []string // context block types (e.g. api or endpoint)
	// contains filtered or unexported fields
}

func New

func New() *Error

func (*Error) Context added in v1.9.0

func (e *Error) Context(name string) *Error

Context appends the given context block type to the existing ones.

func (*Error) Error

func (e *Error) Error() string

func (*Error) HTTPStatus

func (e *Error) HTTPStatus() int

HTTPStatus returns the configured http status code this error should be served with.

func (*Error) IsParent added in v1.9.0

func (e *Error) IsParent() bool

func (*Error) Kind

func (e *Error) Kind(name string) *Error

Kind appends the given kind name to the existing ones. Latest added should be the more specific ones.

func (*Error) Kinds

func (e *Error) Kinds() []string

Kinds returns all configured kinds, the most specific one gets evaluated first.

func (*Error) Label

func (e *Error) Label(name string) *Error

func (*Error) LogError

func (e *Error) LogError() string

LogError contains additional context which should be used for logging purposes only.

func (*Error) Message

func (e *Error) Message(msg string) *Error

func (*Error) Messagef

func (e *Error) Messagef(msg string, args ...interface{}) *Error

func (*Error) Status

func (e *Error) Status(s int) *Error

Status configures the http status-code which will be written along with this error.

func (*Error) Unwrap

func (e *Error) Unwrap() error

func (*Error) With

func (e *Error) With(inner error) *Error

type GoError

type GoError interface {
	error
	HTTPStatus() int
	LogError() string
	Unwrap() error
}

type Template

type Template struct {
	// contains filtered or unexported fields
}
var (
	DefaultHTML *Template
	DefaultJSON *Template
)

func NewTemplate

func NewTemplate(mime, name string, src []byte, logger *logrus.Entry) (*Template, error)

func NewTemplateFromFile

func NewTemplateFromFile(path string, logger *logrus.Entry) (*Template, error)

func (*Template) WithContextFunc

func (t *Template) WithContextFunc(fn http.HandlerFunc) *Template

func (*Template) WithError added in v1.7.0

func (t *Template) WithError(err error) http.Handler

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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