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

Forward errors to Fastify instead of sending custom error pages #27

Merged
merged 3 commits into from
Jan 8, 2018

Conversation

nwoltman
Copy link
Contributor

@nwoltman nwoltman commented Dec 24, 2017

Fixes #17

@mcollina I hope this is what you meant as the solution to #17. Let me know if it isn't. I couldn't find any way to handle 404s with setNotFoundHandler so I made it clear in the docs that 404 errors will be passed to Fastify's error handler.

@mcollina
Copy link
Member

Can you please rephrase the setNotFound problem? It might look like a bug in fastify.

@nwoltman
Copy link
Contributor Author

I rewrote the information about errors and put it in a "Handling Errors" section after the "Options" section.

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, but maybe we might want to do a bugfix release in fastify.

README.md Outdated
[`fastify.setErrorHandler()`](https://www.fastify.io/docs/latest/Server-Methods/#seterrorhandler).

If a request matches the URL `prefix` but a file cannot be found for the request,
a `404 Not Found` error will be created and passed to Fastify's error handler.
Copy link
Member

Choose a reason for hiding this comment

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

I think this behavior might be wrong. We should really flow this through the notFoundHandler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes that would be better. From looking at https://github.com/fastify/fastify/blob/master/fastify.js I think one way to do that would be for fastify-static to have access to Fastify's fourOhFour router so that it can call fourOhFour.lookup(req, res). Do you agree?

Copy link
Member

Choose a reason for hiding this comment

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

I recal (but I might be wrong, I’m from a phone) that Every plugin has its own 404 handler defined, so we should just use that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes you're right. I figured out how to call the 404 handler and I've updated the PR :)

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

if (err.statusCode === 403) return serve403(req, reply.res)
serve500(req, reply.res)
if (err.status === 404) {
fastify._404Context.handler(request, reply)
Copy link
Member

Choose a reason for hiding this comment

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

I’m not a huge fan of accessing a private propery. I think we should expose the handler through a documented method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. What do you think that should look like? fastify.callNotFoundHandler(request, reply)? Or maybe add it to the reply object as reply.notFound()?

Copy link
Member

Choose a reason for hiding this comment

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

I prefer reply.notFound()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay 👍 I'll propose this in Fastify with a PR

@mcollina mcollina merged commit 58832a7 into fastify:master Jan 8, 2018
@nwoltman nwoltman deleted the forward-errors branch August 20, 2018 15:28
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