errors

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 26, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWarningNotification = ApiError{
		Code:   "WAR001",
		Title:  "The warning notification occured.",
		Status: "200",
		// contains filtered or unexported fields
	}

	ErrBadRequest = ApiError{
		Code:   "BRQ001",
		Title:  "The server cannot or will not process the request due to something that is perceived to be a client error",
		Status: "400",
		// contains filtered or unexported fields
	}

	ErrHeadersNotSupported = ApiError{
		Code: "BRQ002",
		Title: `The conditional headers provided in the request are not supported, 
		by the server.`,
		Status: "400",
		// contains filtered or unexported fields
	}

	ErrInvalidAuthenticationInfo = ApiError{
		Code: "BRQ003",
		Title: `The authentication information was not provided in the correct format. 
			Verify the value of Authorization header.`,
		Status: "400",
		// contains filtered or unexported fields
	}

	ErrInvalidHeaderValue = ApiError{
		Code:   "BRQ004",
		Title:  "The value provided in one of the HTTP headers was not in the correct format.",
		Status: "400",
		// contains filtered or unexported fields
	}

	ErrInvalidInput = ApiError{
		Code:   "BRQ005",
		Title:  "One of the request inputs is not valid.",
		Status: "400",
		// contains filtered or unexported fields
	}

	ErrInvalidQueryParameter = ApiError{
		Code:   "BRQ006",
		Title:  "An invalid value was specified for one of the query parameters in the request URI.",
		Status: "400",
		// contains filtered or unexported fields
	}

	ErrInvalidResourceName = ApiError{
		Code:   "BRQ007",
		Title:  "The specified resource name is not valid.",
		Status: "400",
		// contains filtered or unexported fields
	}

	ErrInvalidURI = ApiError{
		Code:   "BRQ008",
		Title:  "The requested URI does not represent any resource on the server.",
		Status: "400",
		// contains filtered or unexported fields
	}

	ErrInvalidJSONDocument = ApiError{
		Code:   "BRQ009",
		Title:  "The specified JSON is not syntatically valid.",
		Status: "400",
		// contains filtered or unexported fields
	}

	ErrInvalidJSONFieldValue = ApiError{
		Code:   "BRQ010",
		Title:  "The value provided for one of the JSON fields in the requested body was not in the correct format.",
		Status: "400",
		// contains filtered or unexported fields
	}

	ErrMD5Mismatch = ApiError{
		Code:   "BRQ011",
		Title:  "The MD5 value specified in the request did not match the MD5 value calculated by the server.",
		Status: "400",
		// contains filtered or unexported fields
	}

	ErrMetadataTooLarge = ApiError{
		Code:   "BRQ012",
		Title:  "The size of the specified metada exceeds the maximum size permitted.",
		Status: "400",
		// contains filtered or unexported fields
	}

	ErrMissingRequiredQueryParam = ApiError{
		Code:   "BRQ013",
		Title:  "A required query parameter was not specified for this request.",
		Status: "400",
		// contains filtered or unexported fields
	}

	ErrMissingRequiredHeader = ApiError{
		Code:   "BRQ014",
		Title:  "A required HTTP header was not specified.",
		Status: "400",
		// contains filtered or unexported fields
	}

	ErrMissingRequiredJSONField = ApiError{
		Code:   "BRQ015",
		Title:  "A required JSON field was not specified in the request body.",
		Status: "400",
		// contains filtered or unexported fields
	}

	ErrOutOfRangeInput = ApiError{
		Code:   "BRQ016",
		Title:  "One of the request inputs is out of range.",
		Status: "400",
		// contains filtered or unexported fields
	}

	ErrOutOfRangeQueryParameterValue = ApiError{
		Code:   "BRQ017",
		Title:  "A query parameter specified in the request URI is outside the permissible range.",
		Status: "400",
		// contains filtered or unexported fields
	}

	ErrUnsupportedHeader = ApiError{
		Code:   "BRQ018",
		Title:  "One of the HTTP headers specified in the request is not supported.",
		Status: "400",
		// contains filtered or unexported fields
	}

	ErrUnsupportedJSONField = ApiError{
		Code:   "BRQ019",
		Title:  "One of the JSON fields specified in the request body is not supported.",
		Status: "400",
		// contains filtered or unexported fields
	}

	ErrUnsupportedQueryParameter = ApiError{
		Code:   "BRQ020",
		Title:  "One of the query parameters in the request URI is not supported.",
		Status: "400",
		// contains filtered or unexported fields
	}

	ErrUnsupportedFilterOperator = ApiError{
		Code:   "BRQ021",
		Title:  "One of the filter operators is not supported.",
		Status: "400",
		// contains filtered or unexported fields
	}

	// STATUS 403, CODE: 'AUTHXX'
	ErrForbidden = ApiError{
		Code:   "FORB1",
		Title:  "client error status response code indicates that the server understood the request but refuses to authorize it",
		Status: "403",
		// contains filtered or unexported fields
	}

	ErrAccountDisabled = ApiError{
		Code:   "AUTH01",
		Title:  "The specified account is disabled.",
		Status: "403",
		// contains filtered or unexported fields
	}

	ErrAuthenticationFailed = ApiError{
		Code: "AUTH02",
		Title: `Server failed to authenticate the request. Make sure the value of 
		Authorization header is formed correctly including the signature.`,
		Status: "403",
		// contains filtered or unexported fields
	}

	ErrInsufficientAccPerm = ApiError{
		Code:   "AUTH03",
		Title:  "The account being accessed does not have sufficient permissions to execute this operation.",
		Status: "403",
		// contains filtered or unexported fields
	}
	ErrAuthInvalidCredentials = ApiError{
		Code:   "AUTH04",
		Title:  "Access is denied due to invalid credentials.",
		Status: "403",
		// contains filtered or unexported fields
	}

	ErrEndpointForbidden = ApiError{
		Code:   "FORB01",
		Title:  "Provided endpoint is forbidden.",
		Status: "403",
		// contains filtered or unexported fields
	}

	// STATUS 404, CODE: 'NTFXXX'
	ErrResourceNotFound = ApiError{
		Code:   "NTF001",
		Title:  "The specified resource does not exists.",
		Status: "404",
		// contains filtered or unexported fields
	}

	// STATUS 405, CODE: "MNAXXX"
	ErrMethodNotAllowed = ApiError{
		Code:   "MNA001",
		Title:  "The resource doesn't support the specified HTTP verb.",
		Status: "405",
		// contains filtered or unexported fields
	}

	// STATUS 406, CODE: "NALXXX"
	ErrNotAcceptable = ApiError{
		Code:   "NA001",
		Title:  "lient error response code indicates that the server cannot produce a response matching the list of acceptable values defined in the request's proactive content negotiation headers",
		Status: "406",
		// contains filtered or unexported fields
	}

	ErrLanguageNotAcceptable = ApiError{
		Code:   "NAL001",
		Title:  "The language provided within the json document is not supported.",
		Status: "406",
		// contains filtered or unexported fields
	}

	ErrLanguageHeaderNotAcceptable = ApiError{
		Code:   "NAL002",
		Title:  "The language provided in the request header is not supported.",
		Status: "406",
		// contains filtered or unexported fields
	}

	// STATUS 409, CODE: "CON001"
	ErrAccountAlreadyExists = ApiError{
		Code:   "CON001",
		Title:  "The Specified account already exists.",
		Status: "409",
		// contains filtered or unexported fields
	}

	ErrResourceAlreadyExists = ApiError{
		Code:   "CON002",
		Title:  "The specified resource already exists.",
		Status: "409",
		// contains filtered or unexported fields
	}

	// STATUS 413, CODE: 'RTLXXX'
	ErrRequestBodyTooLarge = ApiError{
		Code:   "RTL001",
		Title:  "The size of the request body exceeds the maximum size permitted.",
		Status: "413",
		// contains filtered or unexported fields
	}

	// STATUS 500, CODE: 'INTXXX'
	ErrInternalError = ApiError{
		Code:   "INT001",
		Title:  "The server encountered an internal error. Please retry the request.",
		Status: "500",
		// contains filtered or unexported fields
	}

	ErrOperationTimedOut = ApiError{
		Code:   "INT002",
		Title:  "The operation could not be completed within the permitted time.",
		Status: "500",
		// contains filtered or unexported fields
	}

	// STATUS 503, CODE: 'UNAVXX'
	ErrServerBusy1 = ApiError{
		Code:   "UNAV01",
		Title:  "The server is currently unable to receive requests. Please retry your request.",
		Status: "503",
		// contains filtered or unexported fields
	}
	ErrServerBusy2 = ApiError{
		Code:   "UNAV02",
		Title:  "Operations per second is over the account limit.",
		Status: "503",
		// contains filtered or unexported fields
	}
)
View Source
var DefaultErrorMap map[unidb.Error]ApiError = map[unidb.Error]ApiError{
	unidb.ErrNoResult:              ErrResourceNotFound,
	unidb.ErrConnExc:               ErrInternalError,
	unidb.ErrCardinalityViolation:  ErrInternalError,
	unidb.ErrDataException:         ErrInvalidInput,
	unidb.ErrIntegrConstViolation:  ErrInvalidInput,
	unidb.ErrRestrictViolation:     ErrInvalidInput,
	unidb.ErrNotNullViolation:      ErrInvalidInput,
	unidb.ErrForeignKeyViolation:   ErrInvalidInput,
	unidb.ErrUniqueViolation:       ErrResourceAlreadyExists,
	unidb.ErrCheckViolation:        ErrInvalidInput,
	unidb.ErrInvalidTransState:     ErrInternalError,
	unidb.ErrInvalidTransTerm:      ErrInternalError,
	unidb.ErrTransRollback:         ErrInternalError,
	unidb.ErrTxDone:                ErrInternalError,
	unidb.ErrInvalidAuthorization:  ErrInsufficientAccPerm,
	unidb.ErrInvalidPassword:       ErrInternalError,
	unidb.ErrInvalidSchemaName:     ErrInternalError,
	unidb.ErrInvalidSyntax:         ErrInternalError,
	unidb.ErrInsufficientPrivilege: ErrInsufficientAccPerm,
	unidb.ErrInsufficientResources: ErrInternalError,
	unidb.ErrProgramLimitExceeded:  ErrInternalError,
	unidb.ErrSystemError:           ErrInternalError,
	unidb.ErrInternalError:         ErrInternalError,
	unidb.ErrUnspecifiedError:      ErrInternalError,
}

DefaultErrorMap contain default mapping of unidb.Error prototype into Error. It is used by default by 'ErrorMapper' if created using New() function.

Functions

This section is empty.

Types

type ApiError

type ApiError struct {
	// ID is a unique identifier for this particular occurrence of a problem.
	ID string `json:"id,omitempty"`

	// Title is a short, human-readable summary of the problem that SHOULD NOT change from occurrence to occurrence of the problem, except for purposes of localization.
	Title string `json:"title,omitempty"`

	// Detail is a human-readable explanation specific to this occurrence of the problem. Like title, this field’s value can be localized.
	Detail string `json:"detail,omitempty"`

	// Status is the HTTP status code applicable to this problem, expressed as a string value.
	Status string `json:"status,omitempty"`

	// Code is an application-specific error code, expressed as a string value.
	Code string `json:"code,omitempty"`

	// Meta is an object containing non-standard meta-information about the error.
	Meta *map[string]interface{} `json:"meta,omitempty"`

	// Err is a non published message container for loggin purpose
	Err error `json:"-"`
	// contains filtered or unexported fields
}

ApiError is an struct representing a JSON API error

func ErrTooManyNestedRelationships

func ErrTooManyNestedRelationships(relationship string) *ApiError

func (*ApiError) AddMeta

func (e *ApiError) AddMeta(key string, value interface{})

AddMeta adds the meta data for given error. Checks if an object has inited meta field.

func (ApiError) Copy

func (e ApiError) Copy() *ApiError

Copy returns the new object that is a copy of given error object.

func (*ApiError) Error

func (e *ApiError) Error() string

ApiError implements the `ApiError` interface.

func (*ApiError) IntStatus

func (e *ApiError) IntStatus() int

IntStatus returns integer status of the error

func (*ApiError) WithDetail

func (e *ApiError) WithDetail(detail string) *ApiError

WithDetail sets the detail for given error and then returns the error.

func (*ApiError) WithStatus

func (e *ApiError) WithStatus(status int) *ApiError

WithStatus sets the ApiError status

type ErrorMapper

type ErrorMapper struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

ErrorMapper defines the database unidb.Error one-to-one mapping into neuron APIError. The default error mapping is defined in package variable 'DefaultErrorMap'.

func NewDBMapper

func NewDBMapper() *ErrorMapper

NewDBMapper creates new error handler with already inited ErrorMap

func (*ErrorMapper) Handle

func (r *ErrorMapper) Handle(dberr *unidb.Error) (*ApiError, error)

Handle enables unidb.Error handling so that proper ErrorObject is returned. It returns ErrorObject if given database error exists in the private error mapping. If provided dberror doesn't have prototype or no mapping exists for given unidb.Error an application 'error' would be returned. Thread safety by using RWMutex.RLock

func (*ErrorMapper) LoadCustomErrorMap

func (r *ErrorMapper) LoadCustomErrorMap(errorMap map[unidb.Error]ApiError)

LoadCustomErrorMap enables replacement of the ErrorMapper default error map. This operation is thread safe - with RWMutex.Lock

func (*ErrorMapper) UpdateErrorEntry

func (r *ErrorMapper) UpdateErrorEntry(
	dberr unidb.Error,
	apierr ApiError,
)

UpdateErrorEntry changes single entry in the Error Handler error map. This operation is thread safe - with RWMutex.Lock

type MultipleErrors

type MultipleErrors []*ApiError

MultipleErrors is the wrapper over error slice implement error interface

func (MultipleErrors) Error

func (m MultipleErrors) Error() string

Error implements error interface

Jump to

Keyboard shortcuts

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