immobiliare/fastify-sentry

Validation errors are overridden with HTTP 500

wyozi opened this issue ยท 4 comments

wyozi commented

Hey, I'm not sure what would be the best approach for this but I don't think the current status quo is correct either.

Let's say there's a route

  fastify.get('/someroute', {
    schema: {
      querystring: {
        type: 'object',
        properties: {
          dob: { type: 'string', format: 'date' },
        },
        required: ['dob']
      }
    }
  }, (req, res) => {
    return res.send('foo')
  })

Now, if with fastify-sentry I try to call this route with an invalid date of birth, I'm getting {"statusCode":500,"error":"Internal Server Error","message":"Something went wrong"}. Without fastify-sentry I get the more sensible {"statusCode":400,"error":"Bad Request","message":"querystring/dob must match format \"date\""}

IMO these format errors should be fully excluded from fastify-sentry and returned to the client as is.

Seems like one approach (described here https://www.fastify.io/docs/latest/Reference/Validation-and-Serialization/#validation-messages-with-other-validation-libraries) would be to check if validation property exists on the error, and in those cases let it pass through

Hi @wyozi! ๐Ÿ‘‹

We're on vacation right now but we'll come back at you at the start of the next week :)

wyozi commented

@simonecorsi no worries, have a great vacation :)

dnlup commented

Hi @wyozi , I agree with you and I like the approach you suggested. I'll try to put something together and get back to you. Thanks for reporting this ๐Ÿ˜‰

๐ŸŽ‰ This issue has been resolved in version 4.1.1 ๐ŸŽ‰

The release is available on:

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€