Nitro · Request

NITRO0018Preserve intentional HTTP errors in Nitro handlers

Report local intentional 4xx H3 errors replaced by HTTP 500 in a catch.

Why it happens

Replacing an intentional client error with HTTP 500 hides the response contract from callers.

Fix

Rethrow H3 errors before converting unexpected failures to HTTP 500.

Example

Preserve intentional H3 errors

Before

try { throw createError({ statusCode: 401 }) } catch { throw createError({ statusCode: 500 }) }

After

try { throw createError({ statusCode: 401 }) } catch (error) { if (isError(error)) throw error; throw createError({ statusCode: 500 }) }

Verify the fix

Run only this rule after editing so the report stays focused on the diagnostic you are closing:

pnpm vite-doctor . --framework nitro --rules nitro/h3/no-http-error-masking
Copyright © 2026