restify / restify/node-restify

unexpected error code for 'ResourceNotFoundError'

Open
#1,496 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Critical Unconfirmed Waiting on Response
Dominant language
JavaScript
Stars
10.7k
Forks
975
Avg merge
1d 6h
Merged PRs (30d)
5

Description

Bug Report

Restify Version

5.2.0

Node.js Version

7.10.1

Expected behaviour

// trigger this error when some in-existing route being called
server.on('NotFound', (req, res, err, cb) => {
  if (err instanceof errors.ResourceNotFoundError) {
    // should get here
  }

  cb();
});

Actual behaviour

// trigger this error when some in-existing route being called
server.on('NotFound', (req, res, err, cb) => {
  req.log.info(JSON.stringify(err, null, 2)); // { "code": "ResourceNotFound", "message": "/xxxx does not exist" }
  req.log.info(err.toString()); // ResourceNotFoundError: /xxxx does not exist
  req.log.info(err.code); // Error
  if (err instanceof errors.ResourceNotFoundError) {
    // never get here
  }

  cb();
});

Repro case

  1. create a error handler for NotFound error (though I assume there should have a ResourceNotFoundError)
  2. call API server with an in-existing route.

Contributor guide

Open the contributing guide

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 at the server.on('NotFound') handler and reproduce a request to an in-existing route with the reported Restify and Node.js versions. Trace where ResourceNotFoundError is created and how its code is assigned; done means the handler receives the expected error instance and behavior, with a regression test covering the repro.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
api, 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.