should this package expose FastifyError?
good first issue
<!--
Before you submit an issue we recommend you visit [Fastify Help](https://github.com/fastify/help) and ask any questions you have or mention any problems you've had getting started with Fastify.
**Please read this entire template before posting any issue. If you ignore these instructions
and post an issue here that does not follow the instructions, your issue might be closed,
locked, and assigned the `missing discussion` label.**
-->
## 🚀 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
```js
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
}
}
}
```
18 条评论