Skip to content

fix: use the status code as the error body when it has no name - #170

Merged
Phillip9587 merged 2 commits into
pillarjs:masterfrom
johnnyhuirilef:fix/unknown-status-message
Oct 21, 2026
Merged

Phillip9587 merged 2 commits into
pillarjs:masterfrom
johnnyhuirilef:fix/unknown-status-message

Conversation

@johnnyhuirilef

Copy link
Copy Markdown
Contributor

Fixes #169

Hi! 🙂 In production, getErrorMessage() falls back to statuses.message[status]. A valid error status code that has no name, such as 499, gave undefined, and the body was <pre>undefined</pre>.

This change adds the status code itself as the last fallback, the same as res.sendStatus() in Express. Codes that have a name keep their name. The HTTP/1 reason phrase for these codes is still unknown, from Node, and this change does not touch it.

Tests: one new case in test/test.js for status 499 in production. It fails without the change. I also added a line to HISTORY.md under unreleased.

Happy to change anything you prefer 🙌

In production, getErrorMessage() fell back to statuses.message[status], which is undefined for a valid error status that has no name, such as 499. The response body was <pre>undefined</pre>. Fall back to the status code itself, as res.sendStatus() does in Express.

@Phillip9587 Phillip9587 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Phillip9587

Copy link
Copy Markdown
Contributor

I think the workflow failures are from supertest (see expressjs/body-parser#772). Can you pin supertest to 7.3.0 for now?

@Phillip9587
Phillip9587 merged commit 55e9f2c into pillarjs:master Oct 21, 2026
14 checks passed
@Phillip9587

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Production error body is undefined for a status code that has no name

2 participants