Skip to content

fix(evlog): respect status/statusCode on Error instances#218

Merged
HugoRCD merged 3 commits intoHugoRCD:mainfrom
benhid:fix/parse-error
Mar 21, 2026
Merged

fix(evlog): respect status/statusCode on Error instances#218
HugoRCD merged 3 commits intoHugoRCD:mainfrom
benhid:fix/parse-error

Conversation

@benhid
Copy link
Copy Markdown
Contributor

@benhid benhid commented Mar 21, 2026

🔗 Linked issue

Resolves #217

📚 Description

parseError() has three branches for determining the HTTP status of an error:

  1. Objects with a data property → extracts status from the data (covers EvlogError, FetchError)
  2. Error instances → hardcoded 500
  3. Everything else → hardcoded 500

Branch 2 is ignoring any .status or .statusCode property sitting on the error object. This is a problem for frameworks that attach HTTP status to their native error classes, such as NestJS: when adding ValidationPipe with a class-validator DTO, NestJS throws BadRequestException (HTTP 400). BadRequestException extends HttpException extends Error: it has no data property, so it falls through to Branch 2 and gets hardcoded as 500.

Fix

The library already has extractErrorStatus() in shared/errors.ts (used by the middleware layer) which does exactly what was needed. The fix is a one-line change in Branch 2 to call extractErrorStatus(error) instead of hardcoding 500.

Tests

Added 5 new test cases under describe('Error instances with status properties'):

  • .status on Error → respected (NestJS HttpException pattern)
  • .statusCode on Error → respected (H3/Nitro pattern)
  • .status preferred over .statusCode when both exist
  • Plain Error without status → still returns 500 (backward compat)
  • Non-numeric .status → falls back to 500

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 21, 2026

@benhid is attempting to deploy a commit to the HRCD Projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions bot added the bug Something isn't working label Mar 21, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 21, 2026

Thank you for following the naming conventions! 🙏

@HugoRCD HugoRCD changed the title fix(evlog): respect status/statusCode on Error instances fix(evlog): respect status/statusCode on Error instances Mar 21, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 21, 2026

npm i https://pkg.pr.new/evlog@218
npm i https://pkg.pr.new/@evlog/nuxthub@218

commit: d2042df

@HugoRCD HugoRCD self-assigned this Mar 21, 2026
@HugoRCD HugoRCD merged commit 453a548 into HugoRCD:main Mar 21, 2026
12 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] parseError() always returns status 500 for NestJS-native errors

2 participants