Giter Site home page Giter Site logo

Comments (6)

mcollina avatar mcollina commented on June 3, 2024

Was it working in some cases before this? Or has it always been buggy?

from fastify.

mcollina avatar mcollina commented on June 3, 2024

A PR with a fix would really be nice.

from fastify.

Eomm avatar Eomm commented on June 3, 2024

Can replicate with:

const t = require('tap')
const test = t.test
const Fastify = require('.')

test('Fastify should throw on wrong options', async t => {
  const app = Fastify()

  app.addHook('onError', async (req, res, error) => {
    t.pass('onError called')
  })

  app.setErrorHandler((error, req, res) => {
    t.pass('errorHandler called')
    if (error.message === 'unauthorized') {
      return res.code(401).send('unauthorized')
    }

    throw error
  })

  app.get('/should_not_be_logged', {
    onRequest: async () => {
      throw new Error('unauthorized')
    }
  }, async (req, res) => {
    res.send('OK')
  })

  app.get('/should_be_logged', {
    onRequest: async () => {
      throw new Error('unhandled error')
    }
  }, async (req, res) => {
    res.send('OK')
  })

  await app.ready()

  const res = await app.inject({
    method: 'GET',
    url: '/should_not_be_logged'
  })
  t.same(res.statusCode, 401)

  const res2 = await app.inject({
    method: 'GET',
    url: '/should_be_logged'
  })
  t.same(res2.statusCode, 500)

  t.end()
})

We should check.

In v3 I get:

# Subtest: Fastify should throw on wrong options
    ok 1 - errorHandler called
    ok 2 - should be equivalent
    ok 3 - errorHandler called
    ok 4 - onError called
    ok 5 - should be equivalent
    1..5
ok 1 - Fastify should throw on wrong options # time=55.848ms

In v4.10.0:

# Subtest: Fastify should throw on wrong options
    ok 1 - onError called
    ok 2 - errorHandler called
    ok 3 - should be equivalent
    ok 4 - onError called
    ok 5 - errorHandler called
    not ok 6 - unhandled error // memory error

It may me think if we have outdated docs, but for sure we must add a test to assert the order

from fastify.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.