Skip to content

Commit cbfc8d7

Browse files
committed
fix(connect): correct errorHandler
1 parent 783fd57 commit cbfc8d7

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

Diff for: src/connect/errorHandler.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"use strict";
22
export default function () {
33
return function errorHandling(err, req, res, next) {
4-
console.error(err.stack);
5-
res.status(500).send(err.message);
4+
res.writeHead(404);
5+
res.write(err.message);
6+
res.end();
67
next();
78
};
89
}

Diff for: test/connect/hello-test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ describe("connect", function () {
1414
describe("errorHandler", function () {
1515
beforeEach(function (done) {
1616
let app = connect();
17-
app.use(errorHandler());
1817
app.use((req, res, next) => {
1918
next(new Error("wrong"));
2019
});
20+
app.use(errorHandler());
2121
server = http.createServer(app).listen(3000, done);
2222
});
2323
afterEach(function () {
2424
server && server.close();
2525
});
26-
it("should return 500 status response", function () {
26+
it("should return 404 status response", function () {
2727
return fetch("http://localhost:3000")
2828
.then(res => res.status)
2929
.then(status => {
30-
assert(status, 500);
30+
assert(status, 404);
3131
});
3232
});
3333

0 commit comments

Comments
 (0)