express
express copied to clipboard
feat: add deprecation warnings for invalid sendStatus parameters to prepare for Express v6
Summary
Implements deprecation warnings for invalid status codes passed to res.sendStatus(), as recommended by maintainers. This provides a smooth migration path from the current throwing behavior to stricter validation planned for Express 6.
Background
Previously, res.sendStatus() threw a TypeError for non-number inputs. This PR introduces deprecation warnings for such inputs in Express 5, maintaining backward compatibility while preparing for Express 6, where these inputs will throw errors.
Changes Made
-
Deprecation Warning: Emits warnings for non-number status codes using Express's
depdmodule - Graceful Fallback: Invalid inputs now return status 500 instead of throwing
- Express 6 Migration Path: Warning messages clearly state that errors will be thrown in Express 6
-
Comprehensive Tests: Added test cases for
undefined,BigInt, andstringinputs -
Safe Serialization: Uses
String()to safely convert invalid values in warnings
Backward Compatibility
- No breaking changes; existing valid code continues to work seamlessly
- Invalid inputs warn instead of causing immediate crashes
- Provides clear, actionable warnings to help developers fix issues before migrating to Express 6
Test Results
All 1,242 tests pass, including the new comprehensive sendStatus test coverage validating fallback behavior and deprecation logic.
Implementation Details
- Uses Express's standard
depddeprecation system consistent with other Express warnings - Follows established Express patterns and error messaging
- Provides clear, actionable warning messages for maintainers and users