-
-
Notifications
You must be signed in to change notification settings - Fork 21
Closed
Labels
good first issueGood for newcomersGood for newcomers
Description
🚀 Feature Proposal
should export FastifyError function so it can be used with err instanceOf FastifyError in plain JavaScript
is there a reason this is not currently exposed? seems like the use-case is primarily focused on TypeScript, any reason we shouldn't have access to it for plain JS.
Motivation
in a Fastify errorHandler, you want to intercept errors and check what they are
Example
const { FastifyError } = require('fastify-error')
const { DatabaseError } = require('pg-protocol/dist/messages')
module.exports = function (error, request, reply) {
// write to log
request.log.fatal({ ...error }, error.message)
if (error instanceOf FastifyError) {
// do stuff
}
if (error instanceof SyntaxError) {
// do other stuff
}
if (error.validation) {
// handle input validation errors
}
if (error instanceof DatabaseError) {
// replace db query errors with public friendly ones
}
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
good first issueGood for newcomersGood for newcomers