Documentation ¶
Index ¶
- Constants
- Variables
- func GetErrorTitle(err error) string
- func InvalidSchema(err error, context string) error
- func IsErrNoRows(err error) bool
- type Collection
- type Error
- func ErrConstraintViolation(pqerr *pq.Error) Error
- func ErrNoRows(context string) Error
- func Forbidden(context string) Error
- func InternalServerError(context string) Error
- func MethodNotAllowed(context, method string) Error
- func MethodNotAllowedReason(context, method, detail string) Error
- func MissingContext(context string) Error
- func NewConflictError(errContext, errProperty, errDetail string, errValue interface{}) Error
- func NewDataConflictError(errContext, errProperty, errDetail string, errValue interface{}) Error
- func NewDatabaseError(errTitle, context, message string) Error
- func NewError(errTitle, errType, errContext, errProperty, errDetail string, ...) Error
- func NewFromDatabaseError(err error, defaultContext string) Error
- func NewFromJSONError(err error, context string) Error
- func NewFromJSONSchemaError(err gojsonschema.ResultError, context string) Error
- func NewNoDataError(errContext, errProperty, errDetail string, errValue interface{}) Error
- func NewSchemaError(errType, errContext, errProperty, errDetail string, errValue interface{}) Error
- func NewSystemError(errContext, errProperty, errDetail string, errValue interface{}) Error
- func NotFound(context string) Error
- func ServiceUnavailableError(context string) Error
- func Unauthorized(context string) Error
- func UnauthorizedWithDetail(context, property, detail string) Error
- type ErrorConstants
- type ErrorStatusCode
- type Response
- type ResponseError
Constants ¶
const ( TitleBadRequest = "Bad Request" TitleConflict = "Conflict Error" TitleForbidden = "Forbidden" TitleInternalServerError = "Internal Server Error" TitleMethodNotAllowed = "Method Not Allowed" TitleNotFound = "Not Found" TitleSystem = "System Error" )
package constants - standard error responses
const ( TitleDatabaseAccess string = "Access Denied" TitleDatabaseConflict string = "Conflict Error" TitleDatabaseInvalid string = "Invalid Request" TitleDatabaseNoData string = "Data Not Found" TitleDatabaseQuery string = "Query Error" TitleDatabaseService string = "Service Error" MessageNoRows string = "Query returned no records" NilRecord string = "Nil record supplied" )
Database errors -
const (
SchemaValidation = "Schema Validation Error"
)
package constants
Variables ¶
var DBErrorCodeMap = ErrorStatusCode{ TitleDatabaseInvalid: http.StatusBadRequest, TitleDatabaseQuery: http.StatusBadRequest, TitleDatabaseNoData: http.StatusNotFound, TitleDatabaseService: http.StatusServiceUnavailable, TitleDatabaseAccess: http.StatusUnauthorized, }
DBErrorCodeMap - Database error to response code mapping
var JSONErrorCodeMap = ErrorStatusCode{ TitleBadRequest: http.StatusBadRequest, SchemaValidation: http.StatusBadRequest, }
JSONErrorCodeMap - JSON error to response code mapping
var StdErrorCodeMap = ErrorStatusCode{ TitleBadRequest: http.StatusBadRequest, TitleConflict: http.StatusConflict, TitleForbidden: http.StatusForbidden, TitleInternalServerError: http.StatusInternalServerError, TitleMethodNotAllowed: http.StatusMethodNotAllowed, TitleNotFound: http.StatusNotFound, TitleServiceUnavailable: http.StatusServiceUnavailable, TitleSystem: http.StatusServiceUnavailable, TitleUnauthorized: http.StatusUnauthorized, }
StdErrorCodeMap - Standard error to response code mapping
Functions ¶
Types ¶
type Collection ¶
type Collection []error
Collection - holds a collection of errors
func NewCollection ¶
func NewCollection() Collection
NewCollection returns a new Error Collection variable.
func (*Collection) Add ¶
func (c *Collection) Add(err error)
Add adds an Error or Collection to the Errors slice.
func (Collection) AsResponseError ¶
func (c Collection) AsResponseError(titleCodeMap ErrorStatusCode) *ResponseError
AsResponseError - returns an error for an api response
func (Collection) Error ¶
func (c Collection) Error() string
Error implements the error interface for Err.
type Error ¶
type Error struct { Title string `json:"-"` Type string `json:"type,omitempty"` Property string `json:"property,omitempty"` Value string `json:"value,omitempty"` Context string `json:"context,omitempty"` Detail string `json:"detail"` // Fatal - Internal flag to indicate all processing should stop when other errors may continue Fatal bool `json:"-"` // default false // contains filtered or unexported fields }
Error - Intended to be end user friendly error text messages, used in APIs etc
func ErrConstraintViolation ¶
ErrConstraintViolation -
func MethodNotAllowedReason ¶
MethodNotAllowedReason -
func NewConflictError ¶
NewConflictError -
func NewDataConflictError ¶
NewDataConflictError -
func NewDatabaseError ¶
NewDatabaseError -
func NewError ¶
func NewError(errTitle, errType, errContext, errProperty, errDetail string, errValue interface{}) Error
NewError -
func NewFromDatabaseError ¶
NewFromDatabaseError - convert a pq.Error to a Error
func NewFromJSONSchemaError ¶
func NewFromJSONSchemaError(err gojsonschema.ResultError, context string) Error
NewFromJSONSchemaError -
func NewNoDataError ¶
NewNoDataError -
func NewSchemaError ¶
NewSchemaError -
func NewSystemError ¶
NewSystemError -
func ServiceUnavailableError ¶
ServiceUnavailableError -
func UnauthorizedWithDetail ¶
UnauthorizedWithDetail -
func (Error) AsResponse ¶
func (e Error) AsResponse(titleCodeMap ErrorStatusCode) *Response
AsResponse -
func (Error) AsResponseError ¶
func (e Error) AsResponseError(titleCodeMap ErrorStatusCode) *ResponseError
AsResponseError -
type ErrorConstants ¶
ErrorConstants -
func (ErrorConstants) Add ¶
func (ec ErrorConstants) Add(name, value string)
Add - add an error constant
func (ErrorConstants) Merge ¶
func (ec ErrorConstants) Merge(constants map[string]string)
Merge - merge a set of error constants
type ErrorStatusCode ¶
ErrorStatusCode - map an error constant to an error status code
func (ErrorStatusCode) Add ¶
func (esc ErrorStatusCode) Add(name string, value int)
Add - add an error status code
func (ErrorStatusCode) Merge ¶
func (esc ErrorStatusCode) Merge(constants map[string]int)
Merge - add a set of error status codes
type ResponseError ¶
type ResponseError struct { Code int `json:"code"` Title string `json:"title"` Detail string `json:"detail,omitempty"` // TODO: possibly remove - keeping for backward compatibility during transition Errors []Error `json:"errors,omitempty"` }
ResponseError -
func (ResponseError) Error ¶
func (re ResponseError) Error() string