Skip to content

Commit 0b12ff6

Browse files
committed
[Gordon] added the error handling example
1 parent 3299028 commit 0b12ff6

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

error_handler_example.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const express = require("express");
2+
const app = express();
3+
4+
app.get("/", function(req, res, next) {
5+
// assume some error happens
6+
const err = new Error("Unexpected network error");
7+
next(err);
8+
});
9+
10+
app.get("/", function(req, res, next) {
11+
console.log("You should not see this line in the console.");
12+
});
13+
14+
app.use(function(err, req, res, next) {
15+
res.status(500);
16+
res.send({ error: "unknown error" });
17+
});
18+
19+
const server = app.listen(3000, function() {
20+
console.log("Application started....");
21+
});

0 commit comments

Comments
 (0)