H3 · H30015
Throw an HTTPError instead of a plain object
Flags throw statements in H3 handlers that throw an object literal such as { statusCode: 404 }.
Run this rule
pnpm vite-doctor . --rules h3/errors/no-throw-plain-object
Why it matters
H3 v2 turns a thrown value that is not an Error into an unhandled 500 and drops its fields. H3 v1 passed it through createError(), so code migrated from v1 that throws { statusCode } now answers every such error with 500.
Recommended fix
Throw an HTTPError, such as throw new HTTPError({ status: 404, message: "Not found" }) or throw HTTPError.status(404).
Useful links
Example
Throw an HTTPError
Before
export default defineHandler(() => {
throw { statusCode: 404, message: "Not found" }
})
After
export default defineHandler(() => {
throw new HTTPError({ status: 404, message: "Not found" })
})