API Action throw error on failed JSON decode

API Action throw error on failed JSON decode feature request - in this case, for NodeJS.

Example incident:

2022-10-07T22:38:56.516025928Z SyntaxError: Unexpected token N in JSON at position 619
2022-10-07T22:38:56.516066364Z     at JSON.parse (<anonymous>)
2022-10-07T22:38:56.516075231Z     at IncomingMessage.<anonymous> (/opt/node_app/lib/modules/api.js:97:41)
2022-10-07T22:38:56.516079138Z     at IncomingMessage.emit (node:events:402:35)
2022-10-07T22:38:56.516082184Z     at endReadableNT (node:internal/streams/readable:1343:12)
2022-10-07T22:38:56.516085259Z     at processTicksAndRejections (node:internal/process/task_queues:83:21)

This is a silent error, only discoverable by looking at logs. This feature request is to explicitly throw an error if such error occurs. Failure to throw an error on failed JSON decode may lead to unpredictable app behaviour, such as Repeat steps acting erroneously due to no longer iterating an array, but a string

This particular error happened with a JSON containing a “NaN” value, which I guess is not JSON-compliant - fixes have been applied on the API being queried to prevent the return of NaN values

Community Page
Last updated: