Skip to content

Commit

Permalink
Wrap the main logic call in a catch to avoid a crash on error
Browse files Browse the repository at this point in the history
  • Loading branch information
confused-Techie committed Dec 19, 2023
1 parent ee5ecaa commit 2c9c60d
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/setupEndpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,22 @@ const endpointHandler = async function(node, req, res) {

let obj;

if (node.endpoint.endpointKind === "raw") {
await node.logic(req, res, context);
// If it's a raw endpoint, they must handle all other steps manually
return;

} else {
obj = await node.logic(params, context);
try {
if (node.endpoint.endpointKind === "raw") {
await node.logic(req, res, context);
// If it's a raw endpoint, they must handle all other steps manually
return;

} else {
obj = await node.logic(params, context);
}
} catch(err) {
// The main logic request has failed. We will generate our own return obj,
// and exit.
obj = new context.sso();
obj.notOk().addContent(err)
.addMessage("An unexpected error has occurred.")
.addShort("server_error");
}

if (typeof node.postLogic === "function") {
Expand Down

0 comments on commit 2c9c60d

Please sign in to comment.