aspis.internal.utils
Functions
|
A decorator to handle custom exceptions by mapping them to specific error types. |
- aspis.internal.utils.error_ctx(fn)[source]
A decorator to handle custom exceptions by mapping them to specific error types.
- Parameters:
fn (Callable[P, R]) – The function to be wrapped and executed.
- Returns:
The wrapped function with custom error handling.
- Return type:
Callable[P, R]
- Raises:
CustomError – A custom error instance based on the aspis_errors mapping, if a match is found.
Exception – The original exception, if no match is found in aspis_errors.
Example
>>> @error_ctx ... def risky_function(): ... raise ValueError("An error occurred") ... >>> risky_function() # Raises a custom error if ValueError is mapped in `aspis_errors`.