Documentation ¶
Index ¶
- Constants
- Variables
- type ApplicationError
- func NewBadRequestError(traceId, code, message string) *ApplicationError
- func NewConfigError(traceId, code, message string) *ApplicationError
- func NewConflictError(traceId, code, message string) *ApplicationError
- func NewConnectionError(traceId, code, message string) *ApplicationError
- func NewError(message string) *ApplicationError
- func NewErrorFromDescription(description *ErrorDescription) *ApplicationError
- func NewFileError(traceId, code, message string) *ApplicationError
- func NewInternalError(traceId, code, message string) *ApplicationError
- func NewInvalidStateError(traceId, code, message string) *ApplicationError
- func NewInvocationError(traceId, code, message string) *ApplicationError
- func NewNotFoundError(traceId, code, message string) *ApplicationError
- func NewUnauthorizedError(traceId, code, message string) *ApplicationError
- func NewUnknownError(traceId, code, message string) *ApplicationError
- func NewUnsupportedError(traceId, code, message string) *ApplicationError
- func WrapError(err error, message string) *ApplicationError
- func (e *ApplicationError) Error() string
- func (e *ApplicationError) WithCause(cause error) *ApplicationError
- func (e *ApplicationError) WithCauseString(cause string) *ApplicationError
- func (e *ApplicationError) WithCode(code string) *ApplicationError
- func (e *ApplicationError) WithDetails(key string, value any) *ApplicationError
- func (e *ApplicationError) WithStatus(status int) *ApplicationError
- func (e *ApplicationError) WithTraceId(traceId string) *ApplicationError
- func (e *ApplicationError) Wrap(err error) *ApplicationError
- type ErrorDescription
Constants ¶
const ( Unknown = "Unknown" Internal = "Internal" Misconfiguration = "Misconfiguration" InvalidState = "InvalidState" NoResponse = "NoResponse" FailedInvocation = "FailedInvocation" FileError = "FileError" BadRequest = "BadRequest" 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 ¶
var ApplicationErrorFactory *_TApplicationErrorFactory = &_TApplicationErrorFactory{}
ApplicationErrorFactory is a factory to recreate exceptions from ErrorDescription values passed through the wire.
see ErrorDescription see ApplicationError
var ErrorDescriptionFactory = &_TErrorDescriptionFactory{}
ErrorDescriptionFactory is a 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
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]any `json:"details"` TraceId string `json:"trace_id"` StackTrace string `json:"stack_trace"` Cause string `json:"cause"` }
ApplicationError Defines a base class to defive various application exceptions.
Most languages have own definition of base exception (error) types. However, this class is implemented symmetrically in all languages supported by PipServices toolkit. It allows to create portable implementations and support proper error propagation in microservices calls.
Error propagation means that when microservice implemented in one language calls microservice(s) implemented in a different language(s), errors are returned throught the entire call chain and restored in their original (or close) type.
Since number of potential exception types is endless, PipServices toolkit supports only 12 standard categories of exceptions defined in ErrorCategory. This ApplicationException class acts as a basis for all other 12 standard exception types.
Most exceptions have just free-form message that describes occured error. That may not be sufficient to create meaninful error descriptions. The ApplicationException class proposes an extended error definition that has more standard fields:
message: is a human-readable error description category: one of 12 standard error categories of errors status: numeric HTTP status code for REST invocations code: a unique error code, usually defined as "MY_ERROR_CODE" trace_id: a unique transaction id to trace execution through a call chain details: map with error parameters that can help to recreate meaningful error description in other languages stack_trace: a stack trace cause: original error that is wrapped by this exception ApplicationException class is not serializable. To pass errors through the wire it is converted into ErrorDescription object and restored on receiving end into identical exception type. see ErrorCategory see ErrorDescription
func NewBadRequestError ¶
func NewBadRequestError(traceId, code, message string) *ApplicationError
NewBadRequestError Creates an error instance and assigns its values.
see ErrorCategory Parameters: - traceId 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(traceId, code, message string) *ApplicationError
NewConfigError creates an error instance and assigns its values.
see ErrorCategory Parameters: - traceId 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(traceId, code, message string) *ApplicationError
NewConflictError creates an error instance and assigns its values.
see ErrorCategory Parameters: - traceId 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(traceId, code, message string) *ApplicationError
NewConnectionError creates an error instance and assigns its values.
see ErrorCategory Parameters: - traceId 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
NewError creates a new instance of application error and assigns its message.
Parameters: message string an error message Returns: *ApplicationError generated new ApplicationError
func NewErrorFromDescription ¶
func NewErrorFromDescription(description *ErrorDescription) *ApplicationError
NewErrorFromDescription Recreates ApplicationError object from description. It tries to restore original exception type using type or error category fields.
Parameters: description: ErrorDescription a serialized error description received as a result of remote call Returns: *ApplicationError
func NewFileError ¶
func NewFileError(traceId, code, message string) *ApplicationError
NewFileError creates an error instance and assigns its values.
see ErrorCategory Parameters: - traceId 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(traceId, code, message string) *ApplicationError
NewInternalError creates an error instance and assigns its values.
see ErrorCategory Parameters: - traceId 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(traceId, code, message string) *ApplicationError
NewInvalidStateError creates an error instance and assigns its values.
see ErrorCategory Parameters: - traceId 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(traceId, code, message string) *ApplicationError
NewInvocationError creates an error instance and assigns its values.
see ErrorCategory Parameters: - traceId 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(traceId, code, message string) *ApplicationError
NewNotFoundError creates an error instance and assigns its values.
see ErrorCategory Parameters: - traceId 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(traceId, code, message string) *ApplicationError
NewUnauthorizedError creates an error instance and assigns its values.
see ErrorCategory Parameters: - traceId 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(traceId, code, message string) *ApplicationError
NewUnknownError creates an error instance and assigns its values.
see ErrorCategory Parameters: - traceId 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(traceId, code, message string) *ApplicationError
NewUnsupportedError creates an error instance and assigns its values.
see ErrorCategory Parameters: - traceId 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
WrapError wrap error by ApplicationError struct and sets message
Parameters: - err error an error what neet to wrap - message string error message Returns: *ApplicationError
func (*ApplicationError) Error ¶
func (e *ApplicationError) Error() string
Error return string error message
func (*ApplicationError) WithCause ¶
func (e *ApplicationError) WithCause(cause error) *ApplicationError
WithCause add cause to ApplicationError
Parameters: cause error a cause error object Returns: *ApplicationError
func (*ApplicationError) WithCauseString ¶
func (e *ApplicationError) WithCauseString(cause string) *ApplicationError
WithCauseString add cause to ApplicationError
Parameters: cause string a cause string describe an error Returns: *ApplicationError
func (*ApplicationError) WithCode ¶
func (e *ApplicationError) WithCode(code string) *ApplicationError
WithCode Add code to ApplicationError
Parameters: code string a error code Returns: *ApplicationError
func (*ApplicationError) WithDetails ¶
func (e *ApplicationError) WithDetails(key string, value any) *ApplicationError
WithDetails add error details to ApplicationError
Parameters: - key string a detail key word - value any an value of detail object Returns: *ApplicationError
func (*ApplicationError) WithStatus ¶
func (e *ApplicationError) WithStatus(status int) *ApplicationError
WithStatus add status to ApplicationError
Parameters: status int a status code Returns: *ApplicationError
func (*ApplicationError) WithTraceId ¶
func (e *ApplicationError) WithTraceId(traceId string) *ApplicationError
WithTraceId add trace Id to ApplicationError
Parameters: traceId string a trace id string Returns: *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 Returns: *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]any `json:"details"` TraceId string `json:"trace_id"` Cause string `json:"cause"` StackTrace string `json:"stack_trace"` }
ErrorDescription seializeable error description. It is use to pass information about errors between microservices implemented in different languages. On the receiving side ErrorDescription is used to recreate exception object close to its original type without missing additional details.
category - Standard error category cause - Original error wrapped by this exception code - A unique error code trace_id - A unique transaction id to trace execution throug call chain details - A map with additional details that can be used to restore error description in other languages message - A human-readable error description (usually written in English) stack_trace - Stack trace of the exception status - HTTP status code associated with this error type type - Data type of the original error
func NewErrorDescription ¶
func NewErrorDescription(err any) *ErrorDescription
NewErrorDescription creates a serializable ErrorDescription from error object.
Parameters: err any an error object Returns: *ErrorDescription a serializeable ErrorDescription object that describes the error.
Source Files ¶
- ApplicationError.go
- ApplicationErrorFactory.go
- BadRequestError.go
- ConfigError.go
- ConflictError.go
- ConnectionError.go
- ErrorCategory.go
- ErrorDescription.go
- ErrorDescriptionFactory.go
- FileError.go
- InternalError.go
- InvalidStateError.go
- InvocationError.go
- NotFoundError.go
- UnauthorizedError.go
- UnknownError.go
- UnsupportedError.go
- doc.go