Skip to content

Commit

Permalink
Merge pull request #1060 from RoadieHQ/fix-jsonata-error-handling
Browse files Browse the repository at this point in the history
fix jsonata error handling
  • Loading branch information
punkle authored Jul 21, 2023
2 parents 8390d7d + 88c96b8 commit 1ca38a6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/violet-flowers-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@roadiehq/scaffolder-backend-module-utils': patch
---

Adds error handling for the `JSONata` scaffolder action.
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,19 @@ export function createJSONataAction() {
},
},
async handler(ctx) {
const expression = jsonata(ctx.input.expression);
const result = expression.evaluate(ctx.input.data);
try {
const expression = jsonata(ctx.input.expression);
const result = expression.evaluate(ctx.input.data);

ctx.output('result', result);
ctx.output('result', result);
} catch (e: any) {
const message = e.hasOwnProperty('message')
? e.message
: 'unknown JSONata evaluation error';
throw new Error(
`JSONata failed to evaluate the expression: ${message}`,
);
}
},
});
}

0 comments on commit 1ca38a6

Please sign in to comment.