fastify / fastify/help

[onError][reply] hide sensitive data in the error response

Open
#611 4 comments 0 reactions 0 assignees View on GitHub
help wanted
Dominant language
No language data
Stars
68
Forks
8
Avg merge
11h 2m
Merged PRs (30d)
2

Description

Hi guys, sorry if this is trivial, couldn't figure out how to do it.

## 💬 Question here

1. Errors are passed to the `onError` hook, where there is no way to change the body of the reply, but only the status. Am I missing something?
```ts
// call it into onError hook
reply.status(555).send('my error'); // the status is changed, but 'my error' is ignored.
```
Yes, I can mutate the error itself, but that will affect the logs as well.
```ts
error.message = 'my error';
```
2. Following the 1st problem, I thought that sensitive information can be filtered through the JSON scheme, is there an option to specify the response JSON schema for all outgoing traffic? In other words, how to implement the code below to each response without adding this block to each router?
```ts
response: {
'5xx': {
type: 'object',
properties: {
error: {
type: 'string',
},
},
},
},
```
Perhaps there is an easier solution to hide the error message in the response.

Thank you.

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.