If I have a async function with a callback inside like this:
fs.readFile(req.files.file.path, function (err, data) {
return callback(err, data);
});
And I'd like to append or add a simple message to the existing error object (err) (hopefully it's an object, may be string). Whats the best way to do so? I can wrap this error inside another?
Try this:
fs.readFile(req.files.file.path, function (err, data) {
err.myProperty = 'test';
return callback(err, data);
});
Of course you can create another object and make a property "error" with the original err object.