# README
customerror
customerror
provides the base block to create custom errors. It also provides built-in custom errors covering some common cases. A Custom Error provides context - a Message
to an optionally wrapped Err
. Additionally a Code
- for example "E1010", and StatusCode
can be provided. Both static (pre-created), and dynamic (in-line) errors can be easily created. Code
helps a company build a catalog of errors, which helps, and improves customer service.
Install
$ go get github.com/thalesfsp/[email protected]
Usage
See example_test.go
, and customerror_test.go
file.
Documentation
Run $ make doc
or check out online.
Development
Check out CONTRIBUTION.
Release
- Update CHANGELOG accordingly.
- Once changes from MR are merged.
- Tag and release.
Roadmap
Check out CHANGELOG.
# Functions
AddNewLanguage allows setting a new language to the error handling system, seeting the built-in error templates for each error type.
Copy performs a deep copy of the src CustomError into the target CustomError.
Factory creates a validated and pre-defined error to be recalled and thrown later, with or without options.
GetLanguageErrorMap returns the singleton instance of LanguageErrorMap.
GetLanguageErrorTypeMap retrieves the ErrorPrefixMap for a specific language.
GetTemplate retrieves the error template for a specific language and error type.
IsCustomError checks if the error is a `CustomError`.
IsErrorCode checks if the error is a `CustomError` with the specified code.
IsHTTPStatus checks if the error is a `CustomError` with the specified HTTP status code.
IsRetryable checks if the error is a retryable `CustomError`.
MustAddNewLanguage is a wrapper around AddNewLanguage that panics if an error occurs.
MustNewCatalog creates a new Catalog.
New creates a new validated custom error returning it as en `error`.
NewCatalog creates a new Catalog.
NewErrorCode creates a new ErrorCode.
NewErrorPrefixMap creates a new ErrorPrefixMap with the provided templates for each error type.
NewFailedToError is the building block for errors usually thrown when some action failed, e.g: "Failed to create host".
NewHTTPError is the building block for simple HTTP errors, e.g.: Not Found.
NewInvalidError is the building block for errors usually thrown when something fail validation, e.g: "Invalid port".
NewLanguage creates a new Lang.
NewMissingError is the building block for errors usually thrown when required information is missing, e.g: "Missing host".
NewNotFoundError is the building block for errors usually thrown when something is not found, e.g: "Host not found".
NewRequiredError is the building block for errors usually thrown when required information is missing, e.g: "Port is required".
To converts the error to a `CustomError`.
WithError allows to specify an error which will be wrapped by the custom error.
WithErrorCode allows to specify an error code, such as "E1010".
WithField allows to set a field for the error.
WithFields allows to set fields for the error.
WithIgnoreFunc ignores an error if the specified function returns true.
WithIgnoreString ignores an error if the error message, or the the underlying error message contains the specified string.
WithLanguage specifies the language for the error message.
WithMessage allows to specify the error message.
WithRetryable allows to specify if the error is retryable.
WithStatusCode allows to specify the status code, such as "200".
WithTag allows to specify tags for the error.
WithTranslation sets the translation for the error message.
Wrap `customError` around `errors`.
# Constants
No description provided by the author
No description provided by the author
Indicates a failure to perform an action.
No description provided by the author
No description provided by the author
Denotes an invalid input or state.
No description provided by the author
Signifies a missing required element.
Indicates that a requested resource was not found.
No description provided by the author
Denotes a required element that was not provided.
No description provided by the author
# Variables
BuiltInLanguages is a list of built-in prefixes languages.
ErrCatalogErrorNotFound is returned when a custom error isn't found in the catalog.
ErrCatalogInvalidName is returned when a catalog name is invalid.
ErrErrorCodeInvalidCode is returned when an error code is invalid.
ErrInvalidLanguageCode is returned when a language code is invalid.
ErrInvalidLanguageErrorMessage is returned when an error message is invalid.
ErrInvalidLanguageMessageMap is returned when a LanguageMessageMap is invalid.
ErrLanguageNotFound is returned when a requested language is not supported.
ErrorCodeRegex is a regular expression to validate error codes.
ErrTemplateNotFound is returned when a requested error template is not found in the map.
LanguageRegex is a regular expression to validate language codes based on ISO 639-1 and ISO 3166-1 alpha-2.
# Structs
No description provided by the author
CustomError is the base block to create custom errors.
Set is a wrapper around the treeset.Set, providing a collection that stores unique elements in a sorted order.