apherror

package
v0.0.0-...-9ff59ee Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2019 License: BSD-3-Clause Imports: 5 Imported by: 2

Documentation

Overview

Package apherror provides a consistent way to handler JSONAPI related http errors.

Index

Constants

This section is empty.

Variables

View Source
var (
	//HTTPError represents generic http errors
	Errhttp = errors.NewClass("HTTP Error", errors.NoCaptureStack())
	//ErrMessagingReply represents error in request reply messaging
	ErrMessagingReply = newErrorClass("messaging reply error", http.StatusInternalServerError)
	//ErrMessagingReq represents error in request reply messaging
	ErrMessagingReq = newErrorClass("messaging request error", http.StatusInternalServerError)
	//ErrMessagingSub represents error in publish subscribe messaging
	ErrMessagingSub = newErrorClass("messaging subscription error", http.StatusInternalServerError)
	//ErrMessagingPub represents error in publish subscribe messaging
	ErrMessagingPub = newErrorClass("messaging publication error", http.StatusInternalServerError)
	//ErrReqContext represents error in extracting context value from http request
	ErrReqContext = newErrorClass("Unable to retrieve context", http.StatusInternalServerError)
	//ErrOuthExchange represents error in exchanging code for token with oauth server
	ErrOauthExchange = newErrorClass("Unable to exchange token for code", http.StatusInternalServerError)
	//ErrUserRetrieval represents error in retrieving user information from oauth provider
	ErrUserRetrieval = newErrorClass("Unable to retrieve user information", http.StatusInternalServerError)
	//ErrDatabaseQuery represents database query related errors
	ErrDatabaseQuery = newErrorClass("Database query error", http.StatusInternalServerError)
	//ErrNotFound represents the absence of an HTTP resource
	ErrNotFound = newErrorClass("Resource not found", http.StatusNotFound)
	//ErrMethodNotAllowed represents error with unallowed HTTP method
	ErrMethodNotAllowed = newErrorClass("HTTP method not allowed", http.StatusMethodNotAllowed)
	//ErrAuthentication represents the absence of valid authentication credentials
	ErrAuthentication = newErrorClass("Invalid credential for authentication", http.StatusUnauthorized)
	//ErrJSONEncoding represents any json encoding error
	ErrJSONEncoding = newErrorClass("Json encoding error", http.StatusInternalServerError)
	//ErrStructMarshal represents any error with marshalling structure
	ErrStructMarshal = newErrorClass("Structure marshalling error", http.StatusInternalServerError)
	// ErrJWTToken represents errors with jwt token
	ErrJWTToken = newErrorClass("Issue with jwt token", http.StatusInternalServerError)
	//ErrIncludeParam represents any error with invalid include query parameter
	ErrIncludeParam = newErrorClassWithParam("Invalid include query parameter", "include", http.StatusBadRequest)
	//ErrSparseFieldSets represents any error with invalid sparse fieldsets query parameter
	ErrSparseFieldSets = newErrorClassWithParam("Invalid sparse fieldsets query parameter", "fieldsets", http.StatusBadRequest)
	//ErrFilterParam represents any error with invalid filter query paramter
	ErrFilterParam = newErrorClassWithParam("Invalid filter query parameter", "filter", http.StatusBadRequest)
	//ErrNotAcceptable represents any error with wrong or inappropriate http Accept header
	ErrNotAcceptable = newErrorClass("Accept header is not acceptable", http.StatusNotAcceptable)
	//ErrUnsupportedMedia represents any error with unsupported media type in http header
	ErrUnsupportedMedia = newErrorClass("Media type is not supported", http.StatusUnsupportedMediaType)
	//ErrQueryParam represents any error with http query parameters
	ErrQueryParam = newErrorClass("Invalid query parameter", http.StatusBadRequest)
)

Functions

func JSONAPIError

func JSONAPIError(w http.ResponseWriter, err error)

JSONAPIError generate JSONAPI formatted http error from an error object

Types

type Error

type Error struct {
	ID     string       `json:"id,omitempty"`
	Links  *ErrorLinks  `json:"links,omitempty"`
	Status string       `json:"status,omitempty"`
	Code   string       `json:"code,omitempty"`
	Title  string       `json:"title,omitempty"`
	Detail string       `json:"detail,omitempty"`
	Source *ErrorSource `json:"source,omitempty"`
	Meta   interface{}  `json:"meta,omitempty"`
}

Error can be used for all kind of application errors e.g. you would use it to define form errors or any other semantical application problems for more information see http://jsonapi.org/format/#errors

type ErrorLinks struct {
	About string `json:"about,omitempty"`
}

ErrorLinks is used to provide an About URL that leads to further details about the particular occurrence of the problem.

for more information see http://jsonapi.org/format/#error-objects

type ErrorSource

type ErrorSource struct {
	Pointer   string `json:"pointer,omitempty"`
	Parameter string `json:"parameter,omitempty"`
}

ErrorSource is used to provide references to the source of an error.

The Pointer is a JSON Pointer to the associated entity in the request document. The Paramter is a string indicating which query parameter caused the error.

for more information see http://jsonapi.org/format/#error-objects

type HTTPError

type HTTPError struct {
	Errors []Error `json:"errors,omitempty"`
	// contains filtered or unexported fields
}

HTTPError is used for errors

Jump to

Keyboard shortcuts

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