Skip to content

Promise rejection without error #2070

@Eomm

Description

@Eomm

🐛 Bug Report

If an async hook returns a Promise.reject() the flow continue.
This usage of promise should be avoided at all, let me know if you think this is an invalid bug.

Here we should check the err param

fastify/lib/hooks.js

Lines 80 to 82 in 7fa4bdd

function handleReject (err) {
cb(err, request, reply)
}

To Reproduce

Steps to reproduce the behavior:

const fastify = require('./fastify')({ logger: true })
fastify.addHook('onRequest', function (request, reply) {
  return Promise.reject()
})
fastify.get('/', async (request, reply) => { return 'hi' })
fastify.listen(3001)

Expected behavior

The rejection should be managed.

Originally posted by @Eomm in fastify/help#135 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed buggood first issueGood for newcomersv2.xIssue or pr related to Fastify v2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions