Skip to content

Conversation

Copy link

Copilot AI commented Jan 25, 2026

Nitro v3's error handlers were not forwarding H3 HTTPError body properties to clients. The body field should spread properties at the top level of error responses, per H3's error handling contract.

Changes

  • src/runtime/internal/error/dev.ts: Spread error.body at top level of JSON response
  • src/runtime/internal/error/prod.ts: Spread error.body only for non-sensitive errors (respects existing security model)
  • Test coverage: Added regression test with HTTPError containing body properties

Example

throw new HTTPError({
  status: 500,
  message: "Custom error message",
  data: { instance: "local" },
  body: { code: "urn:nitro:error-code" }
});

Before:

{
  "error": true,
  "status": 500,
  "message": "Custom error message",
  "data": { "instance": "local" }
}

After:

{
  "error": true,
  "status": 500,
  "message": "Custom error message",
  "data": { "instance": "local" },
  "code": "urn:nitro:error-code"
}

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • workers.cloudflare.com
    • Triggering command: /usr/local/bin/node /usr/local/bin/node --conditions node --conditions production --experimental-import-meta-resolve --require /home/REDACTED/work/nitro/nitro/node_modules/.pnpm/vitest@4.0.17_@edge-runtime+vm@5.0.0_@types+node@25.0.9_jiti@2.6.1_lightningcss@1.31.1_tsx@4.21.0_yaml@2.8.2/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/nitro/nitro/node_modules/.pnpm/vitest@4.0.17_@edge-runtime+vm@5.0.0_@types+node@25.0.9_jiti@2.6.1_lightningcss@1.31.1_tsx@4.21.0_yaml@2.8.2/node_modules/vitest/dist/workers/forks.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Nitro v3 does not forward H3 HTTPError.body to client</issue_title>
<issue_description>### 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

```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@pi0</author><body>
We need to update the default error handlers (https://github.com/nitrojs/nitro/tree/main/src/runtime/internal/error) to be consistent with h3 beahvior (https://github.com/nitrojs/nitro/tree/main/src/runtime/internal/error)</body></comment_new>
</comments>

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI assigned Copilot and pi0 Jan 25, 2026
@vercel
Copy link

vercel bot commented Jan 25, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
nitro.build Ready Ready Preview, Comment Jan 25, 2026 6:00pm

Request Review

- Updated dev.ts and prod.ts to spread error.body properties at top level
- Added test case for HTTPError.body in test fixture
- Tests passing for both dev and prod error handlers

Co-authored-by: pi0 <5158436+pi0@users.noreply.github.com>
- Added fallback to empty object for error.body to prevent runtime errors
- Ensures safe spreading even when error.body is null or undefined

Co-authored-by: pi0 <5158436+pi0@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Nitro v3 not forwarding H3 HTTPError.body to client Fix HTTPError.body forwarding in error handlers Jan 25, 2026
Copilot AI requested a review from pi0 January 25, 2026 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nitro v3 does not forward H3 HTTPError.body to client

2 participants