Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Koa.js handling of node.js set error codes #1460

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/context.js
Expand Up @@ -143,16 +143,18 @@ const proto = module.exports = {
// force text/plain
this.type = 'text';

let statusCode = err.status || err.statusCode;
vijaykrishnavanshi marked this conversation as resolved.
Show resolved Hide resolved

// ENOENT support
if ('ENOENT' === err.code) err.status = 404;
if ('ENOENT' === err.code) statusCode = 404;

// default to 500
if ('number' !== typeof err.status || !statuses[err.status]) err.status = 500;
if ('number' !== typeof statusCode || !statuses[statusCode]) statusCode = 500;

// respond
const code = statuses[err.status];
const code = statuses[statusCode];
const msg = err.expose ? err.message : code;
this.status = err.status;
this.status = err.status = statusCode;
this.length = Buffer.byteLength(msg);
res.end(msg);
},
Expand Down