fastify / fastify/fastify-error

Implement RFC7807

Open
#64 9 comments 0 reactions 0 assignees View on GitHub
enhancement good first issue
Dominant language
JavaScript
Stars
135
Forks
23
PR merge metrics
No merged PRs in 30d

Description

### Prerequisites

- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the feature has not already been requested

### 🚀 Feature Proposal

We could implement a toRFC7807-method, which creates RFC7807-compatible JSON Response to FastifyError and use it in fastify 4 by default.

So we could create a new Error like this
```javascript

const NewError = createError('CODE', 'hey %s, I like your %s %s')
const err = new NewError('alice', 'attitude', 'see you')
```

and then the resulting JSON would be:
```javascript
{
type: "FastifyError",
title: "FastifyError",
status: 500, // <-- statusCode
detail: 'hey alice, I like your attitude', // <-- message
instance: '', // <-- here could be the route
code: 'CODE',
details: { }, // here could be the ajv error codes.
}
```

### Motivation

_No response_

### Example

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.