-1

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?

4

1 回答 1

2

尝试这个:

fs.readFile(req.files.file.path, function (err, data) {
    err.myProperty = 'test';
    return callback(err, data);
});

当然,您可以创建另一个对象并使用原始 err 对象创建一个属性“错误”。

于 2013-07-25T18:45:23.713 回答