errors

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2020 License: MIT Imports: 1 Imported by: 4

Documentation

Overview

Portable and localizable Exceptions classes. Each Exception, in addition to a description and stack trace has a unique string code, details array (which can be used for creating localized strings).

Way to use:

An existing exception class can be used. A child class that extends ApplicationException can we written. A exception can be wrapped around (into?) an existing application exception. Exceptions are serializable. The exception classes themselves are not serializable, but they can be converted to ErrorDescriptions, which are serializable in one language, transferred to the receiving side, and deserialized in another language. After deserialization, the initial exception class can be restored.

Additionally: when transferring an exception from one language to another, the exception type that is closest to the initial exception type is chosen from the exceptions available in the target language.

Index

Constants

View Source
const (
	Unknown          = "Unknown"
	Internal         = "Internal"
	Misconfiguration = "Misconfiguration"
	InvalidState     = "InvalidState"
	NoResponse       = "NoResponse"
	FailedInvocation = "FailedInvocation"
	FileError        = "FileError"
	BadRequest       = "BadRequest"
	Unauthorized     = "Unauthorized"
	NotFound         = "NotFound"
	Conflict         = "Conflict"
	Unsupported      = "Unsupported"
)

Defines standard error categories to application exceptions supported by PipServices toolkit.

BadRequest - Errors due to incorrectly specified invocation parameters. For example: missing or incorrect parameters.

Conflict - Errors raised by conflicts between object versions that were posted by the user and those that are stored on the server.

FailedInvocation - Errors caused by remote calls failed due to unidenfied reasons.

FileError - Errors in read/write local disk operations.

Internal - Internal errors caused by programming mistakes.

InvalidState - Errors caused by incorrect object state.. For example: business calls when the component is not ready.

Misconfiguration - Errors related to mistakes in user-defined configurations.

NoResponse - Errors caused by remote calls timeouted and not returning results. It allows to clearly separate communication related problems from other application errors.

NotFound - Errors caused by attempts to access missing objects.

Unauthorized - Access errors caused by missing user identity (authentication error) or incorrect security permissions (authorization error).

Unknown - Unknown or unexpected errors.

Unsupported - Errors caused by calls to unsupported or not yet implemented functionality.

Variables

View Source
var ErrorDescriptionFactory = &TErrorDescriptionFactory{}

Functions

This section is empty.

Types

type ApplicationError

type ApplicationError struct {
	Message       string                 `json:"message"`
	Category      string                 `json:"category"`
	Status        int                    `json:"status"`
	Code          string                 `json:"code"`
	Details       map[string]interface{} `json:"details"`
	CorrelationId string                 `json:"correlation_id"`
	StackTrace    string                 `json:"stack_trace"`
	Cause         string                 `json:"cause"`
}

func NewBadRequestError

func NewBadRequestError(correlationId, code, message string) *ApplicationError

Creates an error instance and assigns its values. see ErrorCategory Parameters:

  • correlation_id string a unique transaction id to trace execution through call chain.
  • code string a unique error code.
  • message string a human-readable description of the error.

Returns *ApplicationError

func NewConfigError

func NewConfigError(correlationId, code, message string) *ApplicationError

Creates an error instance and assigns its values. see ErrorCategory Parameters:

  • correlation_id string a unique transaction id to trace execution through call chain.
  • code string a unique error code.
  • message string a human-readable description of the error.

Returns *ApplicationError

func NewConflictError

func NewConflictError(correlationId, code, message string) *ApplicationError

Creates an error instance and assigns its values. see ErrorCategory Parameters:

  • correlation_id string a unique transaction id to trace execution through call chain.
  • code string a unique error code.
  • message string a human-readable description of the error.

Returns *ApplicationError

func NewConnectionError

func NewConnectionError(correlationId, code, message string) *ApplicationError

Creates an error instance and assigns its values. see ErrorCategory Parameters:

  • correlation_id string a unique transaction id to trace execution through call chain.
  • code string a unique error code.
  • message string a human-readable description of the error.

Returns *ApplicationError

func NewError

func NewError(message string) *ApplicationError

Creates a new instance of application error and assigns its message. Parameters:

  • message string an error message

Return *ApplicationError generated new ApplicationError

func NewErrorFromDescription

func NewErrorFromDescription(description *ErrorDescription) *ApplicationError

Returns *ApplicationError

func NewFileError

func NewFileError(correlationId, code, message string) *ApplicationError

Creates an error instance and assigns its values. see ErrorCategory Parameters:

  • correlation_id string a unique transaction id to trace execution through call chain.
  • code string a unique error code.
  • message string a human-readable description of the error.

Returns *ApplicationError

func NewInternalError

func NewInternalError(correlationId, code, message string) *ApplicationError

Creates an error instance and assigns its values. see ErrorCategory Parameters:

  • correlation_id string a unique transaction id to trace execution through call chain.
  • code string a unique error code.
  • message string a human-readable description of the error.

Returns *ApplicationError

func NewInvalidStateError

func NewInvalidStateError(correlationId, code, message string) *ApplicationError

Creates an error instance and assigns its values. see ErrorCategory Parameters:

  • correlation_id string a unique transaction id to trace execution through call chain.
  • code string a unique error code.
  • message string a human-readable description of the error.

Returns *ApplicationError

func NewInvocationError

func NewInvocationError(correlationId, code, message string) *ApplicationError

Creates an error instance and assigns its values. see ErrorCategory Parameters:

  • correlation_id string a unique transaction id to trace execution through call chain.
  • code string a unique error code.
  • message string a human-readable description of the error.

Returns *ApplicationError

func NewNotFoundError

func NewNotFoundError(correlationId, code, message string) *ApplicationError

Creates an error instance and assigns its values. see ErrorCategory Parameters:

  • correlation_id string a unique transaction id to trace execution through call chain.
  • code string a unique error code.
  • message string a human-readable description of the error.

Returns *ApplicationError

func NewUnauthorizedError

func NewUnauthorizedError(correlationId, code, message string) *ApplicationError

Creates an error instance and assigns its values. see ErrorCategory Parameters:

  • correlation_id string a unique transaction id to trace execution through call chain.
  • code string a unique error code.
  • message string a human-readable description of the error.

Returns *ApplicationError

func NewUnknownError

func NewUnknownError(correlationId, code, message string) *ApplicationError

Creates an error instance and assigns its values. see ErrorCategory Parameters:

  • correlation_id string a unique transaction id to trace execution through call chain.
  • code string a unique error code.
  • message string a human-readable description of the error.

Returns *ApplicationError

func NewUnsupportedError

func NewUnsupportedError(correlationId, code, message string) *ApplicationError

Creates an error instance and assigns its values. see ErrorCategory Parameters:

  • correlation_id string a unique transaction id to trace execution through call chain.
  • code string a unique error code.
  • message string a human-readable description of the error.

Returns *ApplicationError

func WrapError

func WrapError(err error, message string) *ApplicationError

Wrap error by ApplicationError struct and sets message Parameters:

  • err error an error what neet to wrap
  • message string error message

Return *ApplicationError

func (*ApplicationError) Error

func (e *ApplicationError) Error() string

Return string error message

func (*ApplicationError) WithCause

func (e *ApplicationError) WithCause(cause error) *ApplicationError

Add cause to ApplicationError Parameters:

  • cause error a cause error object

Return *ApplicationError

func (*ApplicationError) WithCauseString

func (e *ApplicationError) WithCauseString(cause string) *ApplicationError

Add cause to ApplicationError Parameters:

  • cause string a cause string describe an error

Return *ApplicationError

func (*ApplicationError) WithCode

func (e *ApplicationError) WithCode(code string) *ApplicationError

Add code to ApplicationError Parameters:

  • code string a error code

Return *ApplicationError

func (*ApplicationError) WithCorrelationId

func (e *ApplicationError) WithCorrelationId(correlationId string) *ApplicationError

Add Correlation Id to ApplicationError Parameters:

  • correlationId string a correlation string

Return *ApplicationError

func (*ApplicationError) WithDetails

func (e *ApplicationError) WithDetails(key string, value interface{}) *ApplicationError

Add error details to ApplicationError Parameters:

  • key string a detail key word
  • value interface{} an value of detail object

Return *ApplicationError

func (*ApplicationError) WithStatus

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

Add status to ApplicationError Parameters:

  • status int a status code

Return *ApplicationError

func (*ApplicationError) Wrap

func (e *ApplicationError) Wrap(err error) *ApplicationError

Wrap error by ApplicationError struct Parameters:

  • err error an error what neet to wrap

Return *ApplicationError

type ErrorDescription

type ErrorDescription struct {
	Type          string                 `json:"type"`
	Category      string                 `json:"category"`
	Status        int                    `json:"status"`
	Code          string                 `json:"code"`
	Message       string                 `json:"message"`
	Details       map[string]interface{} `json:"details"`
	CorrelationId string                 `json:"correlaion_id"`
	Cause         string                 `json:"cause"`
	StackTrace    string                 `json:"stack_trace"`
}

func NewErrorDescription

func NewErrorDescription(err interface{}) *ErrorDescription

Creates a serializable ErrorDescription from error object. Parameters:

err interface{}
an error object

Returns *ErrorDescription a serializeable ErrorDescription object that describes the error.

type TApplicationErrorFactory

type TApplicationErrorFactory struct{}
var ApplicationErrorFactory *TApplicationErrorFactory = &TApplicationErrorFactory{}

func (*TApplicationErrorFactory) Create

Returns *ApplicationError

type TErrorDescriptionFactory

type TErrorDescriptionFactory struct{}

Factory to create serializeable ErrorDescription from ApplicationException or from arbitrary errors. The ErrorDescriptions are used to pass errors through the wire between microservices implemented in different languages. They allow to restore exceptions on the receiving side close to the original type and preserve additional information. see ErrorDescription see ApplicationError

func (*TErrorDescriptionFactory) Create

func (c *TErrorDescriptionFactory) Create(err interface{}) *ErrorDescription

Creates a serializable ErrorDescription from error object. Parameters:

err error
an error object

Returns *ErrorDescription a serializeable ErrorDescription object that describes the error.

Jump to

Keyboard shortcuts

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