When sending error with next(error) callback, response sent to client does not contain optionnal properties of my new Error Object created with makeConstructor restify-errors module.
Env : Node v12.18.3 with ESM loader (type: "module") in package.json
Example :
import errs from 'restify-errors';
const TestError = errs.makeConstructor("TestError", {
statusCode: 500,
info: {errcode: "ERR_GENERIC"},
message:"App Error"
});
const tmp = new TestError();
console.log("tmp.info exists : ", JSON.stringify(tmp.info));
console.log("But this is sent to client when next(tmp) called : ", JSON.stringify(tmp));
Print :
tmp.info exists : {"errcode":"ERR_GENERIC"}
But this is sent to client when next(tmp) called : {"code":"Test","message":"App Error"}
It seems to be caused by JSON.stringify that only check for ownProperties (it don't look for prototype chain).