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.
var exceptionName = "MyError";
console.log('logging the exception'+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.
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 success.codes 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.
Thanks@Diego Zuluaga ! node js doesn't generate error state so this will not work.