Error Handler
ErrorHandler is used to handle errors within your FuncHandlers
. Each FuncHandler
has its own ErrorHandler
class, which is used by default, but you can always create your own by inheriting the abstract class ABCErrorHandler
.
An instance of the ErrorHandler class has only one catcher. The catcher is a data class that includes:
func
- Catcher function;exceptions
- The exceptions to be caught;logging
- Logging the result of the catcher at the levelDEBUG
;ignore_errors
- Ignoring errors that may occur;raise_exception
- Raising an exception if it occurs during the catcher's execution.
To register a catcher in ErrorHandler, you need to use the .__call__()
decorator. This decorator has params:
exceptions
- The exceptions to be caught;logging
- Logging the result of the catcher at the levelDEBUG
;ignore_errors
- Ignoring errors that may occur;raise_exception
- Raising an exception if it occurs during the catcher's execution.
The catcher function always accepts the error object as its first parameter, which has no specific name, and can also accept two optional arguments:
api
- An instance of the API class;event
- The event that came to the handler.
Additionally some parameters from the context and the catcher function can return a value for ReturnManager
.
.run()
method:
handler
- The handler that needs to be processed;event
- The event that came to the handler;api
- An instance of the API class;ctx
- Context instance.