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 conversion of a thrown exceptions with unknown error codes #486

Merged
merged 2 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [Unreleased][unreleased]

- Fix conversion of custom thrown exceptions for response to client

## [3.2.0][] - 2023-12-10

- Remove `EventEmitter` polyfill, use polyfill from metautil 5.0.0
Expand Down
2 changes: 1 addition & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class Server {
} catch (error) {
let code = error.code === 'ETIMEOUT' ? 408 : 500;
if (typeof error.code === 'number') code = error.code;
error.httpCode = code;
error.httpCode = code <= 599 ? code : 500;
return void client.error(code, { id, error });
} finally {
proc.leave();
Expand Down
3 changes: 2 additions & 1 deletion lib/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ class Transport extends EventEmitter {
const message = pass && error ? error.message : status || 'Unknown error';
const reason = `${httpCode}\t${code}\t${error ? error.stack : status}`;
console.error(`${ip}\t${method}\t${url}\t${reason}`);
const packet = { type: 'callback', id, error: { message, code } };
const outCode = pass ? code : httpCode;
const packet = { type: 'callback', id, error: { message, code: outCode } };
this.send(packet, httpCode);
}

Expand Down