http-errors icon indicating copy to clipboard operation
http-errors copied to clipboard

fix: handle NaN status codes by defaulting to 500

Open Ayoub-Mabrouk opened this issue 2 months ago • 1 comments

Previously, when createError(NaN) was called, the status validation would fail to catch NaN because typeof NaN === 'number' is true in JavaScript. This resulted in errors with NaN status codes, which could cause issues in downstream code.

This fix adds an explicit isNaN() check to the status validation logic, ensuring that NaN status codes are properly caught and defaulted to 500.

Additionally, a test case has been added to verify this behavior and prevent regression.

Ayoub-Mabrouk avatar Nov 22 '25 17:11 Ayoub-Mabrouk

I like it 👍

Thanks 😌

Ayoub-Mabrouk avatar Nov 27 '25 14:11 Ayoub-Mabrouk