Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data in createError() is missing in response #907

Open
ijkml opened this issue Oct 28, 2024 · 1 comment
Open

data in createError() is missing in response #907

ijkml opened this issue Oct 28, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@ijkml
Copy link

ijkml commented Oct 28, 2024

Environment

node: 22.6.0
bun: 1.1.33

Reproduction

Run example from repo:

h3/examples/errors.ts

Lines 20 to 25 in 7324eee

throw createError({
status: 500,
message: "Fatal error",
fatal: true,
data: { foo: "bar" },
});

(log below)

Describe the bug

It's currently not possible to use err.data to pass additional data to client-side.

Additional context

#823 (comment)

Logs

{
  "url": "/devices/lol/",
  "statusCode": 500,
  "statusMessage": "",
  "message": "Fatal error",
  "stack": [
    "at createError (./node_modules/h3/dist/index.mjs:78:15)",
    "at badParamError (./.nitro/dev/index.mjs:934:9)",
    "at Object.handler (./.nitro/dev/index.mjs:992:11)",
    "at ./node_modules/h3/dist/index.mjs:1906:43",
    "at process.processTicksAndRejections (node:internal/process/task_queues:95:5)",
    "at async Object.handler (./node_modules/h3/dist/index.mjs:1978:19)",
    "at async Server.toNodeHandle (./node_modules/h3/dist/index.mjs:2270:7)"
  ]
}
@ijkml ijkml added the bug Something isn't working label Oct 28, 2024
@iiio2
Copy link
Contributor

iiio2 commented Nov 3, 2024

@ijkml , according to h3 docs, it is recommended to throw errors instead of returning them using createError utility. You may check and try with it (https://h3.unjs.io/guide/event-handler#responses-types).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants