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

types: add type of this to the not found handler #2102

Merged
merged 2 commits into from
Feb 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion fastify.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ declare namespace fastify {
/**
* Set the 404 handler
*/
setNotFoundHandler(handler: (request: FastifyRequest<HttpRequest>, reply: FastifyReply<HttpResponse>) => void): void
setNotFoundHandler(handler: (this: FastifyInstance<HttpServer, HttpRequest, HttpResponse>, request: FastifyRequest<HttpRequest>, reply: FastifyReply<HttpResponse>) => void): void

/**
* Set a function that will be called whenever an error happens
Expand Down
4 changes: 3 additions & 1 deletion test/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,9 @@ server.get('/test-decorated-inputs', (req, reply) => {
(reply as DecoratedReply).utility()
})

server.setNotFoundHandler((req, reply) => {
server.setNotFoundHandler(function (req, reply) {
this.log.error('not found')
reply.code(404).send()
})

server.setErrorHandler((err, request, reply) => {
Expand Down