Replies: 1 comment 1 reply
|
The shortest supported form in the current API is: throw HTTPError.status(404)or: throw HTTPError.status(404, "Not Found")The current error guide says to send errors by throwing I would not make If the goal is small syntax, |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi, not sure if this has been discussed before, but wanted to share an idea.
Right now when I want to return a 404 from a handler I write:
It would be nice if h3 accepted a simpler shorthand like:
Basically: let the thrown value map to an HTTP error directly, without the
createError({ statusCode: ... })wrapper.createError/new HTTPError({ ... })would still be there for the richer cases (customdata, headers, message, etc.).PR: #1372
Custom strings
We could also tried supporting a string form to carry a message:
But parsing the status out of the string needs a regex and bumps the bundle size a bit, so I left it out of the PR. For messages, sticking with
new HTTPError({ status: 404, message: "Lesson not found" })feels cleaner.All reactions