H3 · Errors

H30014Pass createError() an object, not a status number

Flags createError() called with a bare status code, such as createError(404).

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
Copyright © 2026