Skip to content

Commit fb6edb3

Browse files
committed
Merge branch 'master' of https://github.com/yanhick/middlebot
2 parents 12f1fce + 83d3e17 commit fb6edb3

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

readme.md

+16-3
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,29 @@ npm install middlebot
1919
var app = require('middlebot')();
2020

2121
// Middleware example.
22-
var middleware = function(err, req, res, next) {
22+
var middleware = function(req, res, next) {
2323
// Do stuff here...
2424
next();
2525

2626
// If there was an error call next with an error object.
27-
next(err);
27+
next('oups !');
2828

2929
// Middlewares execution can be stop this way.
3030
res.end();
3131
}
32+
33+
// Error middleware example, only called when a previous middleware
34+
//sent an error or throwed an exception
35+
var errorMiddleware = function(err, req, res, next) {
36+
//handle error...
37+
38+
//calls following error middlewares
39+
next(err);
40+
41+
//next can be called without err to ignore error and resume
42+
//normal middleware execution
43+
next();
44+
}
3245

3346
// Register middleware to be called when ‘myMiddlewares’ is handled.
3447
app.use('myMiddlewares', middleware);
@@ -62,4 +75,4 @@ npm test
6275

6376
## License
6477

65-
MIT
78+
MIT

0 commit comments

Comments
 (0)