Skip to content

Commit

Permalink
fix: only set err.status on statusCode >= 200 (#677)
Browse files Browse the repository at this point in the history
> nodejs.AssertionError: invalid status code: -1

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Bug Fixes**
- Improved error handling to ensure the HTTP status code is valid and
within the correct range.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
fengmk2 authored May 14, 2024
1 parent dbf5b52 commit 668eed2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion app/port/middleware/ErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function ErrorHandler(ctx: EggContext, next: Next) {
}

// http status, default is DEFAULT_SERVER_ERROR_STATUS
ctx.status = err.status || DEFAULT_SERVER_ERROR_STATUS;
ctx.status = (typeof err.status === 'number' && err.status >= 200) ? err.status : DEFAULT_SERVER_ERROR_STATUS;
// don't log NotImplementedError
if (ctx.status >= DEFAULT_SERVER_ERROR_STATUS && err.name !== 'NotImplementedError') {
ctx.logger.error(err);
Expand Down

0 comments on commit 668eed2

Please sign in to comment.