Skip to content

Commit

Permalink
Updates to standards.
Browse files Browse the repository at this point in the history
  • Loading branch information
evert committed Jan 15, 2024
1 parent a981cf0 commit f8ffcb3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ try {
```

Lastly, it the package has an interface that makes it easier to work with the
`application/problem+json` format, as defined in [RFC7807][3]. The interface
`application/problem+json` format, as defined in [RFC9457][3]. The interface
has `type`, `title`, `detail` and `instance` properties, which makes it easier
to write a generic interface that emits this JSON error format.

Expand Down Expand Up @@ -180,7 +180,7 @@ export class Gone extends HttpErrorBase {}
export class LengthRequired extends HttpErrorBase {}
export class PreconditionFailed extends HttpErrorBase {}

export class PayloadTooLarge extends HttpErrorBase {
export class ContentTooLarge extends HttpErrorBase {
retryAfter: number | null;
constructor(detail: string|null = null, retryAfter: number|null = null) {}
}
Expand All @@ -190,7 +190,7 @@ export class UnsupportedMediaType extends HttpErrorBase {}
export class RangeNotSatisfiable extends HttpErrorBase {}
export class ExpectationFailed extends HttpErrorBase {}
export class MisdirectedRequest extends HttpErrorBase {}
export class UnprocessableEntity extends HttpErrorBase {}
export class UnprocessableContent extends HttpErrorBase {}
export class Locked extends HttpErrorBase {}
export class FailedDependency extends HttpErrorBase {}
export class TooEarly extends HttpErrorBase {}
Expand Down Expand Up @@ -218,12 +218,11 @@ export class HttpVersionNotSupported extends HttpErrorBase {}
export class VariantAlsoNegotiates extends HttpErrorBase {}
export class UnsufficientStorage extends HttpErrorBase {}
export class LoopDetected extends HttpErrorBase {}
export class NotExtended extends HttpErrorBase {}
export class NetworkAuthenticationRequired extends HttpErrorBase {}
```

...

[1]: https://github.com/curveball/
[2]: http://koajs.com/
[3]: https://tools.ietf.org/html/rfc7807
[3]: https://tools.ietf.org/html/rfc9457
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Changelog
ESM is the future, so we're dropping CommonJS.
* Now requires Node 18.
* Upgraded to Typescript 5.3.
* To match RFC9110, `UnprocessableEntity` is now `UnprocessableContent`, and
`PayloadToolarge` is now `ContentTooLarge`. The old classes still exist and
have been marked as deprecated.
* Updated references from RFC7807 to RFC9457.


0.5.0 (2023-02-14)
Expand Down
32 changes: 26 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export class PreconditionFailed extends HttpErrorBase {
}

/**
* Emits 413 Payload Too Large.
* Emits 413 Content Too Large
*
* If the status is temporary, it's possible for a server to send a
* Retry-After header to try again. This value may be embeded in this
Expand All @@ -220,9 +220,9 @@ export class PreconditionFailed extends HttpErrorBase {
*
* throw new PayloadTooLarge('Send the large file again in 10 minutes', 600);
*/
export class PayloadTooLarge extends HttpErrorBase {
export class ContentTooLarge extends HttpErrorBase {
httpStatus = 413;
title = 'Payload Too Large';
title = 'Content Too Large';

retryAfter: number | null;

Expand All @@ -234,6 +234,14 @@ export class PayloadTooLarge extends HttpErrorBase {
}
}

/**
* Payload Too Large was the old name of this error, but all instances of
* Payload have been renamed to Content in RFC9110.
*
* @deprecated
*/
export class PayloadTooLarge extends ContentTooLarge {}

/**
* Emits 414 URI Too Long
*/
Expand Down Expand Up @@ -275,13 +283,21 @@ export class MisdirectedRequest extends HttpErrorBase {
}

/**
* Emits 422 Unprocessable Entity
* Emits 422 Unprocessable Content
*/
export class UnprocessableEntity extends HttpErrorBase {
export class UnprocessableContent extends HttpErrorBase {
httpStatus = 422;
title = 'Unprocessable Entity';
}

/**
* RFC9110 renamed this to Unprocessable Content.
*
* @deprecated
*/
export class UnprocessableEntity extends UnprocessableContent {
}

/**
* Emits 423 Locked
*/
Expand Down Expand Up @@ -455,7 +471,11 @@ export class LoopDetected extends HttpErrorBase {
}

/**
* Emits 510 Not Extended
* Emits 510 Not Extended.
*
* This status code has been marked as obsolute.
*
* @deprecated
*/
export class NotExtended extends HttpErrorBase {
httpStatus = 510;
Expand Down

0 comments on commit f8ffcb3

Please sign in to comment.