How can I rethrow an error or exception in nodejs/javascript and include a custom message.
I have the following code
var json = JSON.parse(result);
and I wanted to include the result
content in the exception message should any parsing error occurs. Something like this.
1. try {
2. var json = JSON.parse(result);
3. expect(json.messages.length).to.be(1);
4. } catch(ex) {
5. throw new Error(ex.message + . + JSON response: + result);
6. }
The problem here is that I lose my stack trace.
Is there a way to do it similar to java
?
throw new Error(JSON response: + result, ex);