errors

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package errors contains API specific error implementation. The errors are related with specific neuron-core classes.

Index

Constants

This section is empty.

Variables

View Source
var DefaultClassMapper = &ClassMapper{
	Majors: map[errors.Major]Creator{
		class.MjrCommon:     ErrInternalError,
		class.MjrConfig:     ErrInternalError,
		class.MjrEncoding:   ErrInvalidInput,
		class.MjrLanguage:   ErrLanguageNotAcceptable,
		class.MjrInternal:   ErrInternalError,
		class.MjrQuery:      ErrInvalidQueryParameter,
		class.MjrRepository: ErrServiceUnavailable,
		class.MjrModel:      ErrInternalError,
	},
	Minors: map[errors.Minor]Creator{
		class.MnrEncodingUnmarshal:       ErrInvalidInput,
		class.MnrEncodingMarshal:         ErrInternalError,
		class.MnrQueryFieldset:           ErrInvalidQueryParameter,
		class.MnrQuerySelectedFields:     ErrInternalError,
		class.MnrQueryPagination:         ErrInvalidQueryParameter,
		class.MnrQueryFilter:             ErrInvalidQueryParameter,
		class.MnrQuerySorts:              ErrInvalidQueryParameter,
		class.MnrQueryViolation:          ErrInvalidJSONFieldValue,
		class.MnrQueryInclude:            ErrInvalidQueryParameter,
		class.MnrQueryValue:              ErrInvalidInput,
		class.MnrQueryTransaction:        ErrInternalError,
		class.MnrRepositoryNotImplements: ErrInternalError,
		class.MnrRepositoryConnection:    ErrServiceUnavailable,
		class.MnrRepositoryReplica:       ErrInternalError,
	},
	Class: map[errors.Class]Creator{
		class.EncodingUnmarshalCollection:      ErrTypeConflict,
		class.EncodingUnmarshalUnknownField:    ErrInvalidResourceName,
		class.EncodingUnmarshalInvalidID:       ErrInvalidJSONFieldValue,
		class.EncodingUnmarshalInvalidFormat:   ErrInvalidJSONDocument,
		class.EncodingUnmarshalInvalidTime:     ErrInvalidJSONFieldValue,
		class.EncodingUnmarshalInvalidType:     ErrInvalidJSONFieldValue,
		class.EncodingUnmarshalValueOutOfRange: ErrInputOutOfRange,
		class.EncodingUnmarshalNoData:          ErrInvalidInput,

		class.QueryFieldsetDuplicate:    ErrInvalidQueryParameter,
		class.QueryFieldsetTooBig:       ErrInvalidQueryParameter,
		class.QueryFieldsetUnknownField: ErrInvalidResourceName,
		class.QueryFieldsetInvalid:      ErrInternalError,

		class.QueryFilterUnknownCollection:   ErrInvalidResourceName,
		class.QueryFilterUnknownField:        ErrInvalidResourceName,
		class.QueryFilterUnknownOperator:     ErrInvalidQueryParameter,
		class.QueryFilterMissingRequired:     ErrMissingRequiredQueryParameter,
		class.QueryFilterUnsupportedField:    ErrUnsupportedField,
		class.QueryFilterUnsupportedOperator: ErrUnsupportedFilterOperator,
		class.QueryFilterLanguage:            ErrLanguageNotAcceptable,
		class.QueryFilterInvalidField:        ErrInvalidQueryParameter,
		class.QueryFilterInvalidFormat:       ErrInvalidQueryParameter,

		class.QuerySortField:         ErrInvalidResourceName,
		class.QuerySortFormat:        ErrInvalidQueryParameter,
		class.QuerySortRelatedFields: ErrUnsupportedQueryParameter,
		class.QuerySortTooManyFields: ErrInvalidQueryParameter,

		class.QueryPaginationAlreadySet: ErrInternalError,

		class.QueryViolationCheck:       ErrInvalidJSONFieldValue,
		class.QueryViolationUnique:      ErrResourceAlreadyExists,
		class.QueryViolationNotNull:     ErrInvalidJSONFieldValue,
		class.QueryValueValidation:      ErrInvalidJSONFieldValue,
		class.QueryValueUnaddressable:   ErrInternalError,
		class.QueryValueType:            ErrInternalError,
		class.QueryValuePrimary:         ErrInvalidJSONFieldValue,
		class.QueryValueMissingRequired: ErrInvalidInput,
		class.QueryValueNoResult:        ErrResourceNotFound,

		class.QueryIncludeTooMany: ErrInvalidQueryParameter,

		class.RepositoryNotFound:       ErrInternalError,
		class.RepositoryAuthPrivileges: ErrInternalError,

		class.CommonParseBrackets: ErrInvalidQueryParameter,
		class.ModelSchemaNotFound: ErrInternalError,
	},
}

DefaultClassMapper is the default error classification mapper.

Functions

func ErrAccountAlreadyExists

func ErrAccountAlreadyExists() *jsonapi.Error

ErrAccountAlreadyExists creating account failed - user already exists.

func ErrAccountDisabled

func ErrAccountDisabled() *jsonapi.Error

ErrAccountDisabled provided account is disabled.

func ErrBadRequest

func ErrBadRequest() *jsonapi.Error

ErrBadRequest is the API error thrown on bad request

func ErrEndpointForbidden

func ErrEndpointForbidden() *jsonapi.Error

ErrEndpointForbidden forbidden access above given API endpoint.

func ErrForbidden

func ErrForbidden() *jsonapi.Error

ErrForbidden server understood the request but refuses to authorize it.

func ErrHashMismatch

func ErrHashMismatch() *jsonapi.Error

ErrHashMismatch returns when the hash value specified in the request didn't match the one stored/computed by the server.

func ErrHeadersNotSupported

func ErrHeadersNotSupported() *jsonapi.Error

ErrHeadersNotSupported errors thrown when the provided HTTP headers are not supported by the server

func ErrIDConflict

func ErrIDConflict() *jsonapi.Error

ErrIDConflict defines an error when the primary field value doesn't match endpoint's defined id.

func ErrInputOutOfRange

func ErrInputOutOfRange() *jsonapi.Error

ErrInputOutOfRange one of the request inputs were out of range.

func ErrInsufficientAccountPermissions

func ErrInsufficientAccountPermissions() *jsonapi.Error

ErrInsufficientAccountPermissions provided account has insufficient permissions for given request.

func ErrInternalError

func ErrInternalError() *jsonapi.Error

ErrInternalError server encountered internal error.

func ErrInvalidAuthenticationInfo

func ErrInvalidAuthenticationInfo() *jsonapi.Error

ErrInvalidAuthenticationInfo defines the error when the authentication fails.

func ErrInvalidAuthorizationHeader

func ErrInvalidAuthorizationHeader() *jsonapi.Error

ErrInvalidAuthorizationHeader server failed to authenticate the request due to invalid authorization header.

func ErrInvalidCredentials

func ErrInvalidCredentials() *jsonapi.Error

ErrInvalidCredentials provided invalid account credentials - access denied.

func ErrInvalidHeaderValue

func ErrInvalidHeaderValue() *jsonapi.Error

ErrInvalidHeaderValue responsed when some HTTP header was not in a valid format.

func ErrInvalidInput

func ErrInvalidInput() *jsonapi.Error

ErrInvalidInput returned when provided request input is not valid.

func ErrInvalidJSONDocument

func ErrInvalidJSONDocument() *jsonapi.Error

ErrInvalidJSONDocument error returned when the specified JSON structure is not syntetically valid.

func ErrInvalidJSONFieldValue

func ErrInvalidJSONFieldValue() *jsonapi.Error

ErrInvalidJSONFieldValue error returned when one or more of the specified JSON fields was not in a correct format.

func ErrInvalidQueryParameter

func ErrInvalidQueryParameter() *jsonapi.Error

ErrInvalidQueryParameter one of the query parameters has invalid value or format.

func ErrInvalidResourceName

func ErrInvalidResourceName() *jsonapi.Error

ErrInvalidResourceName defines an error when the specified resource name is not valid.

func ErrInvalidURI

func ErrInvalidURI() *jsonapi.Error

ErrInvalidURI error returned when the URI is not recognized by the server.

func ErrLanguageHeaderNotAcceptable

func ErrLanguageHeaderNotAcceptable() *jsonapi.Error

ErrLanguageHeaderNotAcceptable provided request headers contains not supported language.

func ErrLanguageNotAcceptable

func ErrLanguageNotAcceptable() *jsonapi.Error

ErrLanguageNotAcceptable languages provided in the request are not supported.

func ErrMetadataTooLarge

func ErrMetadataTooLarge() *jsonapi.Error

ErrMetadataTooLarge the size of the specified metadata exceeds the limits.

func ErrMethodNotAllowed

func ErrMethodNotAllowed() *jsonapi.Error

ErrMethodNotAllowed given method is not allowed for the specified URI

func ErrMissingRequiredHeader

func ErrMissingRequiredHeader() *jsonapi.Error

ErrMissingRequiredHeader one of the required HTTP headers were not specified in the request.

func ErrMissingRequiredModelField

func ErrMissingRequiredModelField() *jsonapi.Error

ErrMissingRequiredModelField one of the required model fields were not specified in the request body

func ErrMissingRequiredQueryParameter

func ErrMissingRequiredQueryParameter() *jsonapi.Error

ErrMissingRequiredQueryParameter returns when one or more of the query parameter is missing for the request.

func ErrNotAcceptable

func ErrNotAcceptable() *jsonapi.Error

ErrNotAcceptable one of the header contains values that are not possible to get the response by the server.

func ErrOperationTimedOut

func ErrOperationTimedOut() *jsonapi.Error

ErrOperationTimedOut the operation could not be completed within the permitted time.

func ErrQueryParameterValueOutOfRange

func ErrQueryParameterValueOutOfRange() *jsonapi.Error

ErrQueryParameterValueOutOfRange one of the specified query parameters in the request URI is outside the permissible range.

func ErrRequestBodyTooLarge

func ErrRequestBodyTooLarge() *jsonapi.Error

ErrRequestBodyTooLarge the size of the request body exceeds the maximum permitted size.

func ErrResourceAlreadyExists

func ErrResourceAlreadyExists() *jsonapi.Error

ErrResourceAlreadyExists the specified resource already exists.

func ErrResourceNotFound

func ErrResourceNotFound() *jsonapi.Error

ErrResourceNotFound provided resource doesn't exists.

func ErrServiceUnavailable

func ErrServiceUnavailable() *jsonapi.Error

ErrServiceUnavailable the server is currently unable to receive requests.

func ErrTooManyOperationsPerAccount

func ErrTooManyOperationsPerAccount() *jsonapi.Error

ErrTooManyOperationsPerAccount too many requests for given account.

func ErrTypeConflict

func ErrTypeConflict() *jsonapi.Error

ErrTypeConflict defines an error when the data 'type' doesn't match endpoint's defined 'type'.

func ErrUnsupportedField

func ErrUnsupportedField() *jsonapi.Error

ErrUnsupportedField one of the fields specified in the request is not supported.

func ErrUnsupportedFilterOperator

func ErrUnsupportedFilterOperator() *jsonapi.Error

ErrUnsupportedFilterOperator one of the filter operators is not supported.

func ErrUnsupportedHeader

func ErrUnsupportedHeader() *jsonapi.Error

ErrUnsupportedHeader one of the HTTP headers specified in the request is not supported.

func ErrUnsupportedQueryParameter

func ErrUnsupportedQueryParameter() *jsonapi.Error

ErrUnsupportedQueryParameter one of the query parameters in the request URI is not supported.

func ErrWarningNotification

func ErrWarningNotification() *jsonapi.Error

ErrWarningNotification warns on response with some value.

func MapError

func MapError(err error) []*jsonapi.Error

MapError maps the 'err' input error into slice of 'Error'. The function uses DefaultClassMapper for error mapping. The logic is the same as for DefaultClassMapper.Errors method.

Types

type ClassMapper

type ClassMapper struct {
	Majors map[errors.Major]Creator
	Minors map[errors.Minor]Creator
	Class  map[errors.Class]Creator
}

ClassMapper is the neuron errors classification mapper. It creates the 'Error' from the provided error.

func (*ClassMapper) Errors

func (c *ClassMapper) Errors(err error) []*jsonapi.Error

Errors gets the slice of 'Error' from the provided 'err' error. The mapping is based on the 'most specific classification first' method. If the error is 'errors.ClassError' the function gets it's class. The function checks classification occurrence based on the priority:

  • Class
  • Minor
  • Major

If no mapping is provided for given classification - an internal error is returned.

type Creator

type Creator func() *jsonapi.Error

Creator is the function used to create new Error instance.

type MultiError

type MultiError []*jsonapi.Error

MultiError is the multiple Error wrapper.

func (MultiError) Status

func (m MultiError) Status() int

Status gets the most significant api error status.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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