wrapError method
If any error is thrown by reduce
or before
, you have the chance
to further process it by using wrapError
. Usually this is used to wrap
the error inside of another that better describes the failed action.
For example, if some action converts a String into a number, then instead of
throwing a FormatException you could do:
wrapError(error, _) => UserException("Please enter a valid number.", cause: error)
If you want to disable the error you can return null
. For example, if you want
to disable errors of type MyException
:
wrapError(error, _) => (error is MyException) ? null : error
IMPORTANT: The action wrapError behaves differently from the global WrapError
because returning null
will DISABLE the error, while in the global WrapError
returning null
will keep the error unchanged. This difference is confusing,
and I will, in the future, change the global WrapError to match the action.
Implementation
Object? wrapError(Object error, StackTrace stackTrace) => error;