Skip to content

Conversation

@justinbeaty
Copy link

Resolves #7

Currently if you create an error and don't provide a message, it will be an empty string. This PR makes it so the default message is used from messagesByCodes[].

Examples:

throw new HttpError(401) // message: Unauthorized
throw new UnauthorizedError() // message: Unauthorized
throw new UnauthorizedError({ key1: 'value1' }) // message: Unauthorized

Also added a message !== null check since typeof null === 'object' and it would throw if you called new UnauthorizedError(null). Not sure why someone would do that, but just for extra safety.

@justinbeaty
Copy link
Author

@mgcrea is this what you envisioned?

@justinbeaty justinbeaty force-pushed the topic-default-message branch from 955ae1e to 980888c Compare November 12, 2025 15:28
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.

Add default message to align with the original http-errors package?

1 participant