-
-
Notifications
You must be signed in to change notification settings - Fork 776
Open
Labels
Description
Environment
- node: v22.14.0
- nitro: v3.0.1-alpha.2
Reproduction
Repro on Stackblitz: https://stackblitz.com/edit/github-kwi8pcgj
- Open Repro Project on Stackblitz
- Click Button "Missing HTTPError.body" in preview UI (this calls /api/error)
- Validate that error response does not include custom body property
Describe the bug
Nitro v3 using H3 v2 introduces a new way to handle errors with HTTPError. HTTPError allows to add custom properties through either data (appended as data property in the error response) or body (appended as top level property in the error response.
With Nitro v3, properties passed via body are not forwarded to the client.
Additional context
Example error handling:
throw new HTTPError({
status: 500,
message: 'Custom error message',
data: {
instance: 'local',
},
body: { code: 'urn:nitro:missing-error-code' },
});Current response:
{
"error": true,
"url": "http://localhost:61126/api/error",
"status": 500,
"message": "Custom error message",
"data": {
"instance": "local"
},
"stack": [... ]
}Expected response:
{
"error": true,
"url": "http://localhost:61126/api/error",
"status": 500,
"message": "Custom error message",
"data": {
"instance": "local"
},
"code": "urn:nitro:missing-error-code", // <-- this one should be passed to the client too
"stack": [... ]
}Make sure to test with an API client. If you open the url in dev mode via browser (in this case
.../api/error), nitro renders the youch error page where you will find the additional body properties.
Logs
pi0, tatwater and schplittCopilot and tatwater