Skip to content

Nitro v3 does not forward H3 HTTPError.body to client #3976

@toblu96

Description

@toblu96

Environment

  • node: v22.14.0
  • nitro: v3.0.1-alpha.2

Reproduction

Repro on Stackblitz: https://stackblitz.com/edit/github-kwi8pcgj

  1. Open Repro Project on Stackblitz
  2. Click Button "Missing HTTPError.body" in preview UI (this calls /api/error)
  3. 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

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingv3

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions