Skip to content

server _routeErrorResponse avoiding uncaughtException by only sending response when not sent - #1568

Merged
hekike merged 5 commits into
restify:masterfrom
beckend:_routeErrorResponse
Nov 21, 2017
Merged

hekike merged 5 commits into
restify:masterfrom
beckend:_routeErrorResponse

Conversation

@beckend

@beckend beckend commented Nov 17, 2017 •

Copy link
Copy Markdown
Contributor

middlewares and routes which send response normally, however server listeners such as MethodNotAllowed will trigger the route error handler and send response regardless if payload has been sent or not and causes an uncaughtException needlessly.

Closes:

@hekike

hekike commented Nov 20, 2017

Copy link
Copy Markdown
Contributor

Thanks for the contribution!

I applied a very similar fix on the 7.x branch: #1561 with e315641 and I think it's also related to the #1557

@beckend could you please add a test to cover this case?

@beckend

beckend commented Nov 20, 2017

Copy link
Copy Markdown
Contributor Author

@hekike test proven

Comment thread test/server.test.js Outdated
) {
SERVER.on('MethodNotAllowed', function(req, res, error, next) {
res.json(405, { status: 'MethodNotAllowed' });
var nextHasErrored;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do this:

try {
    next();
} catch (err) {
    t.fail('next() should not throw error when header has already been sent');
}
t.end();

@hekike

hekike commented Nov 20, 2017

Copy link
Copy Markdown
Contributor

@beckend thanks, a small comment, otherwise looks great!

@beckend beckend changed the title avoiding uncaughtException by only sending response when not sent server _routeErrorResponse avoiding uncaughtException by only sending response when not sent Nov 20, 2017
@hekike
hekike merged commit cf65c65 into restify:master Nov 21, 2017
@hekike

hekike commented Nov 21, 2017

Copy link
Copy Markdown
Contributor

@beckend thanks for your contribution! Landed as v6.3.4.

hekike added a commit that referenced this pull request Nov 21, 2017
@beckend
beckend deleted the _routeErrorResponse branch November 21, 2017 10:39
hekike added a commit that referenced this pull request Nov 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants