Skip to content

Commit

Permalink
fix: don't leak command failed errors + remove stack returns
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlougheed committed Jan 18, 2024
1 parent cd0254b commit bf816cd
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions helpers/handlers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,27 @@
*/


const GENERIC_MESSAGE =
"An error was encountered while processing this request. See the server logs for more information.";

export const errorHandler = (res, status=500) => err => {
if (status) {
res.status(status);
}

if (err instanceof Error) {
res.json({ok: false, status, message: err.toString(), stack: err.stack.split('\n')});
let message = err.toString();
console.error(`Error encountered (status=${status}): ${message}; stack:\n`, err.stack);
if (message.startsWith("Error: Command failed:")) {
message = GENERIC_MESSAGE;
}
res.json({ok: false, status, message});
} else {
res.json({ok: false, status, message: err});
let message = err;
if (message.startsWith("Error: Command failed:")) {
message = GENERIC_MESSAGE;
}
res.json({ok: false, status, message});
}
res.end();
};
Expand Down

0 comments on commit bf816cd

Please sign in to comment.