Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from Nov 21, 2017

Conversation

beckend
Copy link
Contributor

@beckend beckend commented Nov 17, 2017

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
Copy link
Member

hekike commented Nov 20, 2017

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
Copy link
Contributor Author

beckend commented Nov 20, 2017

@hekike test proven

) {
SERVER.on('MethodNotAllowed', function(req, res, error, next) {
res.json(405, { status: 'MethodNotAllowed' });
var nextHasErrored;
Copy link
Member

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
Copy link
Member

hekike commented Nov 20, 2017

@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
Copy link
Member

hekike commented Nov 21, 2017

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

None yet

2 participants