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

fix: prevent premature close error #149

Merged
merged 4 commits into from
Oct 20, 2020

Conversation

salmanm
Copy link
Member

@salmanm salmanm commented Oct 15, 2020

As reported in fastify/fastify#2616 & #116, the module fails and logs an error when client closes the request prematurely. This PR fixes that by adding a custom errorHandler in the route config so that the specific ERR_STREAM_PREMATURE_CLOSE can be handled in a special way. For all other errors, we still fallback to the default fastify.errorHandler which was introduced in 3.7.0.

Checklist

@salmanm salmanm force-pushed the custom-err-handler branch 2 times, most recently from 88dbb0e to cfad3b5 Compare October 15, 2020 14:18
fastify.errorHandler = (_, __, reply) => {
reply.send('default-error-obj')
}
}
Copy link
Member

Choose a reason for hiding this comment

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

You should also add a test where fastify.errorHandler is undefined.

@salmanm salmanm force-pushed the custom-err-handler branch 2 times, most recently from bd4caaf to d296b94 Compare October 16, 2020 13:24
@salmanm
Copy link
Member Author

salmanm commented Oct 16, 2020

Implemented feedbacks on this PR, but build is still not green until fastify/light-my-request#102 is merged and version is bumped.

@salmanm salmanm force-pushed the custom-err-handler branch from d296b94 to cc76dd0 Compare October 19, 2020 09:35
@salmanm salmanm marked this pull request as ready for review October 19, 2020 09:37
@salmanm salmanm requested a review from mcollina October 19, 2020 09:38
Copy link
Member

@zekth zekth left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@mcollina mcollina merged commit b2f2dd4 into fastify:master Oct 20, 2020
@salmanm salmanm deleted the custom-err-handler branch October 20, 2020 10:00
@jstayton
Copy link

Thank you, @salmanm!

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.

4 participants