express-simulate-errors
express.js middleware which simulates server errors. Use when testing error handling.
Installing
With npm:
$ npm install j-/express-simulate-errors
Use
var simulateErrors = ;// use as middleware for all subsequent handlers...var smallChance = ;app;// ...or use as middleware for a specific routevar bigChance = ;var { /* callback logic */ }app;
If an error is being simulated, next(err)
is called within the middleware. The error can be caught with an errorback function:
app;// errorback function// only called when middleware passes an error object to `next()`app
Syntax
simulateErrors(options)
options
- Optional configurationoptions.chance
- Optional chance of an error occurring. Defined as a value between 0 (0% chance) and 1 (100% chance). Defaults to 1.