H3 · Errors
vite-doctor/h3errorserrorSuggestion
Why it happens
createError() reads the status from an object or a message string. A number is neither, so createError(404) builds a 500 error in both H3 v1 and v2, and clients get a server error instead of the intended status.
Fix
Pass the status in an object, such as createError({ status: 404 }), or use HTTPError.status(404) in H3 v2.
Example
Pass the status in an object
Before
export default defineHandler(() => {
throw createError(404)
})
After
export default defineHandler(() => {
throw createError({ status: 404, message: "Not found" })
})
Verify the fix
Run only this rule after editing so the report stays focused on the diagnostic you are closing:
pnpm vite-doctor . --rules h3/errors/no-numeric-create-error