restify / restify/errors

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

Open
#105 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
144
Forks
30
Avg merge
2d 2h
Merged PRs (30d)
6

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with errs.makeConstructor and the next(error) serialization path described in the example; compare the constructed error's properties with its JSON.stringify output. Reproduce the Node v12.18.3 ESM case, then add a focused test showing that optional constructor properties such as info are included in the serialized response.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.