Fallback
Usage
The Fallback
module allows you to filter your errors.
Works very well in conjunction with other modules!
For example, filtering Circuit Breaker
errors to return a generic error.
const { Circuit, Fallback } = require('mollitia');
const circuit = new Circuit({
options: {
modules: [
new Fallback({
callback (err) {
if (err instanceof MyError) {
return err;
}
return new UnknownError();
}
})
]
}
});
circuit.fn(myFunction).execute()
.catch((err) => {
if (err instanceof MyError) {
} else {
}
});
Options
Name | Description | Default |
---|
callback | The callback, called when the circuit rejects. | Function(Error) |
Events
Name | Description | Params |
---|
execute | Called when the module is executed. | Mollitia.Circuit circuit |
Methods
Name | Description | Returns |
---|
getExecParams | Returns the circuit function parameters. | any[] params |