View Source LenraCommon.Errors.ErrorGenerator (lenra_common v2.8.0-beta.1)
LenraCommon.Errors.ErrorGenerator allows to generate two functions following a list of errors.
The first function returns the error structure and the second returns the {:error, _error_struct}
tuple.
Summary
Functions
This code takes care of generating each function corresponding to errors listed in the @errors
array.
It basically loops through the array and generates two functions for each error
Functions
This code takes care of generating each function corresponding to errors listed in the @errors
array.
It basically loops through the array and generates two functions for each error:
- one that returns the error without metadata
- one that returns the error with metadata.
Here is an example. Imagine that the @errors
array contains the following errors:
[
{:unknown_error, "Unknown error"},
]
The following functions will be generated:
def unknown_error() do
%BusinessError{
message: "Unknown error",
reason: :unknown_error
}
end
def unknown_error(metadata) do
%BusinessError{
message: "Unknown error",
reason: :unknown_error,
data: metadata
}
end