Node JS - Raise exception

Participant V

We are implementing the exception handling framework. much on the lines discussed here

However, There are cases where we are having target calls being made and we want to raise a fault from node js (basically setting http status error codes) but they are not caught in the raise fault policy. To overcome this we are now using Java script to intercept the response from node js code and then raise the fault as discussed in article below. But, facing some issues.

1. How do i break out of the node js code to Javascript. throwException doesn't seem to work as it gives scriptexecution error.


var exceptionName = "MyError";
console.log('logging the exception'+exceptionName)
throw exceptionName;
//resp.end(JSON.stringify("Missing id parameter"));


/*Nonerror code follows */


I alternately can use response.end with some blank message as i would be setting appropriate mesage/codes in raise fault but that doesn't seem to be the best way to break out of error condition. Any suggestions.

2. Also, Is it the optimized way to do so? This needs to be done for all the node js code that we will be writing so thinking from framework perspective.



0 3 497

Not applicable

Given that you're leveraging Node.js and Express.js to deal with the request/response, I'd leverage either res.send or res.end as you mentioned in your message. The only twist that, I'd add to it is to set a response code that triggers fault flow, so you fault rules execute. So something like this, should work:


Also, make sure that don't list 4XX. If this doesn't trigger a fault flow, then definitely use a JS policy or Fault rule to throw the fault. Please reply to confirm if you had to do so, to inform Docs team to document this issue.

0 0 0

Participant V

Thanks@Diego Zuluaga ! node js doesn't generate error state so this will not work.


There is a discussion on this thread below. javascript intercept seems to be the best

0 1 0

Not applicable

Agreed. Hence the need for the JS Policy.

@docs we should capture this workaround.

0 0 0
Top Labels in this Space
Top Solution Authors