Skip to content

Commit

Permalink
fix(Server): handle finished responses in onError
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranet committed May 4, 2020
1 parent 74ac1a8 commit 1166e91
Show file tree
Hide file tree
Showing 3 changed files with 534 additions and 484 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"url": "https://github.com/dirigeants/klasa-dashboard-hooks.git"
},
"scripts": {
"lint": "npx eslint --fix src && npx eslint --fix --config .eslintrcmd.json --ext md guides && npx tslint --fix 'typings/*.ts'",
"test:lint": "npx eslint src && npx tslint 'typings/*.ts' && npx eslint --config .eslintrcmd.json --ext md guides && npx markdownlint guides README.md",
"lint": "npx eslint --fix src && npx eslint --fix --config .eslintrcmd.json --ext md guides",
"test:lint": "npx eslint src && npx eslint --config .eslintrcmd.json --ext md guides && npx markdownlint guides README.md",
"docs": "npx dg --source src --custom guides/.docconfig.json --output dist/docs.json --logging"
},
"dependencies": {
Expand All @@ -33,7 +33,6 @@
"eslint-config-klasa": "github:dirigeants/klasa-lint",
"eslint-plugin-markdown": "^1.0.0",
"markdownlint-cli": "^0.17.0",
"tslint": "^5.16.0",
"typescript": "^3.6.3"
},
"engines": {
Expand Down
5 changes: 5 additions & 0 deletions src/lib/http/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ class Server {
* @param {external:ServerResponse} response The response
*/
onError(error, request, response) {
if (response.finished) {
this.client.emit('error', error);
return;
}

const code = response.statusCode = error.code || error.status || error.statusCode || 500;
response.end((error.length && error) || error.message || http.STATUS_CODES[code]);
}
Expand Down
Loading

0 comments on commit 1166e91

Please sign in to comment.