feat(common): add payment required exception for http 402#16878
Open
LOsioChico wants to merge 1 commit intonestjs:masterfrom
Open
feat(common): add payment required exception for http 402#16878LOsioChico wants to merge 1 commit intonestjs:masterfrom
LOsioChico wants to merge 1 commit intonestjs:masterfrom
Conversation
402 is the only status code in the 400-422 range without a dedicated HttpException subclass. The HttpStatus.PAYMENT_REQUIRED enum entry already exists, but throwing it requires the verbose form 'new HttpException(msg, HttpStatus.PAYMENT_REQUIRED)'. Add PaymentRequiredException mirroring ImATeapotException for symmetry with the other 21 sibling exceptions, export it from the barrel, and extend the parametric tests in http.exception.spec.ts.
Coverage Report for CI Build 0Coverage remained the same at 90.025%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
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.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
@nestjs/commonexports a dedicatedHttpExceptionsubclass for every standard 4xx status code in the 400-422 range, except 402.BadRequestExceptionbad-request.exception.tsUnauthorizedExceptionunauthorized.exception.tsForbiddenExceptionforbidden.exception.tsNotFoundExceptionnot-found.exception.tsMethodNotAllowedExceptionmethod-not-allowed.exception.tsNotAcceptableExceptionnot-acceptable.exception.tsRequestTimeoutExceptionrequest-timeout.exception.tsConflictExceptionconflict.exception.tsGoneExceptiongone.exception.tsPreconditionFailedExceptionprecondition-failed.exception.tsPayloadTooLargeExceptionpayload-too-large.exception.tsUnsupportedMediaTypeExceptionunsupported-media-type.exception.tsImATeapotExceptionim-a-teapot.exception.tsMisdirectedExceptionmisdirected.exception.tsUnprocessableEntityExceptionunprocessable-entity.exception.tsThe status enum already has the entry,
HttpStatus.PAYMENT_REQUIRED = 402, and decorators consuming it work fine:But throwing it requires the verbose form:
instead of the symmetric form available for every other 4xx:
Use case: paywalls, quota walls, "subscription required" responses.
What is the new behavior?
PaymentRequiredExceptionis exported from@nestjs/commonand behaves identically to its siblings:The implementation mirrors
ImATeapotException(same constructor signature, same default-message strategy, samecauseoption support).Files changed:
packages/common/exceptions/payment-required.exception.ts(new, 55 lines).packages/common/exceptions/index.ts(one newexport * fromline, alphabetical position).packages/common/test/exceptions/http.exception.spec.ts(4 one-line insertions: import +getStatustable +getResponsetable +builtInErrorClassesarray). This extends the existing parametric tests and exercises the same status / default-message / cause-propagation paths every other built-in exception is tested for.All 16 tests in
http.exception.spec.tspass locally; lint is clean.Does this PR introduce a breaking change?
Pure addition. No existing identifier is renamed or removed.
Other information
nestjs/docs.nestjs.comonce this lands.PaymentRequiredExceptionmatches theHttpStatus.PAYMENT_REQUIREDenum entry and the IANA registered status text "Payment Required".subject-caserule (single casing style required).