Give concrete HipError subclasses default messages - #120
Open
Sarita-Joshi wants to merge 1 commit into
Open
Conversation
Constructed without a message, each subclass now uses its own: HipBadInputs "Inputs not valid", HipUnauthorized "Unauthorized", HipForbidden "Forbidden", HipNotFound "Resource not found", HipConflict "Conflict", HipInternal "Internal server error". Every string is one the library already put on the wire, so nothing internal changes -- all in-tree throw sites pass an explicit message. This binds the HTTP status and the client-visible message to a single symbol, so a caller can pass the CLASS where an error is wanted and do `new DenialError()` at each throw site: a reusable authorization gate gets a fresh error with its own stack per denial, instead of sharing one prebuilt instance across every request or wrapping the constructor in a factory thunk. An explicit message still wins, including an empty one (`??`, not `||`), and a subclass that declares no default behaves exactly as before. INTERNAL_ERROR_MESSAGE moves to ./errors.js, where it is HipInternal's default, and is re-exported from ./core.js so existing imports are unaffected. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Constructed without a message, each concrete
HipErrorsubclass now uses its own default:HipBadInputsInputs not validHipUnauthorizedUnauthorizedHipForbiddenForbiddenHipNotFoundResource not foundHipConflictConflictHipInternalInternal server errorEvery string is one the library already put on the wire (mongoose loaders' 404, zod helpers' 422, the lifecycle scrub message), and all in-tree throw sites pass an explicit message — so no response changes.
Why: it binds the HTTP status and the client-visible message to a single symbol, so a caller can pass the class where an error is wanted and do
new DenialError()at each throw site. A reusable authorization gate then gets a fresh error with its own stack per denial, instead of sharing one prebuilt instance across every request or wrapping the constructor in a factory thunk:An explicit message still wins, including an empty one (
??, not||), and a subclass that declares no default behaves exactly as before.INTERNAL_ERROR_MESSAGEmoves to./errors.js(it isHipInternal's default) and is re-exported from./core.js, so existing imports are unaffected — verified identical fromhipthrusts,hipthrusts/coreandhipthrusts/errorsin both the CJS and ESM builds.Wire change worth noting: a bare
new HipForbidden()previously produced{"error":""}and now produces{"error":"Forbidden"}. That's the point of the change, but it is visible — additive/minor.No version bump — releases are cut as their own PR.
Checklist
pnpm test,pnpm lint,pnpm typecheck, andpnpm buildpass locallyAlso ran
pnpm format:check,pnpm check:exports,pnpm smoke— all clean; 241 tests pass.🤖 Generated with Claude Code