errors

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package errors provides RFC7807 problem-details and negotiates HTML or JSON responses the HTML response is in the form of a redirect to an error page

Index

Constants

View Source
const (
	// TEXT content-type requested by client
	TEXT content = iota
	// JSON content-type requested by client
	JSON
	// HTML content-type requested by client
	HTML
)
View Source
const (
	// DefaultCookieExpiry is the default expiry time of a cookie
	DefaultCookieExpiry = 60

	// FlashKeyError is used as a flash message for errors
	FlashKeyError = "flash_error"

	// FlashKeyInfo is used as a key for flash messages
	FlashKeyInfo = "flash_info"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BadRequestError

type BadRequestError struct {
	Err     error
	Request *http.Request
}

BadRequestError indicates that the client request cannot be fulfilled

func (BadRequestError) Error

func (e BadRequestError) Error() string

Error implements the error interface

type ErrorReporter

type ErrorReporter struct {
	CookieSettings cookies.Settings
	ErrorPath      string
	// contains filtered or unexported fields
}

ErrorReporter handles sending of errors to clients respecting the context (Accept header)

func (*ErrorReporter) Negotiate

func (e *ErrorReporter) Negotiate(w http.ResponseWriter, r *http.Request, err error)

Negotiate respects content-types, sets the status code and returns error information

type NotFoundError

type NotFoundError struct {
	Err     error
	Request *http.Request
}

NotFoundError is used when a given object cannot be found

func (NotFoundError) Error

func (e NotFoundError) Error() string

Error implements the error interface

type ProblemDetail

type ProblemDetail struct {
	// Type is a URI reference [RFC3986] that identifies the
	// problem type.  This specification encourages that, when
	// dereferenced, it provide human-readable documentation for the problem
	Type string `json:"type"`
	// Title is a short, human-readable summary of the problem type
	Title string `json:"title"`
	// Status is the HTTP status code
	Status int `json:"status"`
	// Detail is a human-readable explanation specific to this occurrence of the problem
	Detail string `json:"detail,omitempty"`
	// Instance is a URI reference that identifies the specific occurrence of the problem
	Instance string `json:"instance,omitempty"`
}

ProblemDetail combines the fields defined in RFC7807

"Note that both "type" and "instance" accept relative URIs; this means that they must be resolved relative to the document's base URI" swagger:model

func ErrBadRequest

func ErrBadRequest(err BadRequestError) *ProblemDetail

ErrBadRequest returns a http.StatusBadRequest

func ErrNotFound

func ErrNotFound(err NotFoundError) *ProblemDetail

ErrNotFound returns a http.StatusNotFound

func ErrRedirectError

func ErrRedirectError(err RedirectError) *ProblemDetail

ErrRedirectError returns a http.StatusTemporaryRedirect

func ErrSecurityError

func ErrSecurityError(err SecurityError) *ProblemDetail

ErrSecurityError returns a http.StatusForbidden

func ErrServerError

func ErrServerError(err ServerError) *ProblemDetail

ErrServerError returns a http.StatusInternalServerError

type RedirectError

type RedirectError struct {
	Err     error
	Request *http.Request
	Status  int
	URL     string
}

RedirectError is a specific error indicating a necessary redirect

func (RedirectError) Error

func (e RedirectError) Error() string

Error implements the error interface

type SecurityError

type SecurityError struct {
	Err     error
	Request *http.Request
}

SecurityError is used when something is not allowed

func (SecurityError) Error

func (e SecurityError) Error() string

Error implements the error interface

type ServerError

type ServerError struct {
	Err     error
	Request *http.Request
}

ServerError is used when an unexpected situation occurred

func (ServerError) Error

func (e ServerError) Error() string

Error implements the error interface

Jump to

Keyboard shortcuts

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