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);
You may want to have a look at the verror module from Joyent, which provides an easy way to wrap errors:
var originError = new Error('No such file or directory');
var err = new VError(originError, 'Failed to load configuration');
console.error(err.message);
This will print:
Failed to load configuration: No such file or directory