Skip to content

[Restify 7] handleUncaughtExceptions incorrectly handles other types of errors #1709

@mridgway

Description

@mridgway
  • Used appropriate template for the issue type
  • Searched both open and closed issues for duplicates of this issue
  • Title adequately and concisely reflects the feature or the bug

Bug Report

Restify Version

Restify 7.x

Node.js Version

Node 8.11.3

Expected behaviour

Turning on handleUncaughtExceptions should trigger uncaughtException handlers only for thrown exceptions that have not been caught.

Actual behaviour

Other exceptions like next(new Error()) or calling a method (like HEAD) that is not handled by the server trigger the uncaughtExceptions handlers.

Repro case

var restify = require('./');

var server = restify.createServer({
    handleUncaughtExceptions: true
});

server.on('uncaughtException', function exceptionHandler(req, res, route, err) {
    res.send(500, 'foo');
});

// Hitting this route incorrectly triggers the uncaughtException handler
server.get('/', function rootGet(req, res, next) {
    next(new Error('Test')); 
});

// Hitting this route correctly triggers the uncaughtException handler
server.get('/throw', function throwGet(req, res, next) {
    throw new Error('Thrown Error');
});

server.listen(3000);

// Hitting `HEAD /` incorrectly triggers the uncaughtException handler with `MethodNotAllowed` error

Cause

The logic for handling errors has been unified between uncaught exceptions and other types of route handling errors, but information on whether an error was uncaught is not retained.

Are you willing and able to fix this?

Yes, I have a branch ready at master...mridgway:fixUncaughtExceptionTrigger

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