Skip to content

Restify next(err) don't serialize extraneous options created by makeConstructor #105

@deguich

Description

@deguich

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions