@web-ts-toolkit/http-errors 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -7
- package/index.d.mts +6 -0
- package/index.d.ts +6 -0
- package/package.json +12 -7
package/README.md
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
# http-errors
|
|
1
|
+
# `@web-ts-toolkit/http-errors`
|
|
2
2
|
|
|
3
|
-
HTTP error classes
|
|
3
|
+
Typed HTTP error classes and structured error payload helpers for backend APIs.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
|
-
|
|
8
|
+
pnpm add @web-ts-toolkit/http-errors
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Highlights
|
|
12
12
|
|
|
13
|
-
-
|
|
14
|
-
-
|
|
13
|
+
- typed 4xx and 5xx error classes
|
|
14
|
+
- `HttpError`, `ClientError`, and `ServerError` base classes
|
|
15
|
+
- machine-readable error metadata
|
|
16
|
+
- helpers for AIP-193 and RFC 9457 payloads
|
|
15
17
|
|
|
16
|
-
##
|
|
18
|
+
## Quick Start
|
|
17
19
|
|
|
18
20
|
```ts
|
|
19
21
|
import { HttpError, UnauthorizedError, ServiceUnavailableError } from '@web-ts-toolkit/http-errors';
|
|
@@ -26,3 +28,17 @@ throw new HttpError(503, 'please try again later');
|
|
|
26
28
|
|
|
27
29
|
throw new ServiceUnavailableError();
|
|
28
30
|
```
|
|
31
|
+
|
|
32
|
+
## Main Exports
|
|
33
|
+
|
|
34
|
+
- `HttpError`
|
|
35
|
+
- specific error classes such as `BadRequestError`, `ForbiddenError`, `NotFoundError`
|
|
36
|
+
- `toAip193ErrorPayload(...)`
|
|
37
|
+
- `toRfc9457ErrorPayload(...)`
|
|
38
|
+
- `toRfc9457ValidationErrorPayload(...)`
|
|
39
|
+
|
|
40
|
+
## Documentation
|
|
41
|
+
|
|
42
|
+
Full package documentation lives in `website/docs/packages/http-errors.md`.
|
|
43
|
+
|
|
44
|
+
- live docs: https://web-ts-toolkit.pages.dev/docs/packages/http-errors
|
package/index.d.mts
CHANGED
|
@@ -72,6 +72,12 @@ declare const toAip193ErrorPayload: (error: HttpErrorShape, fallbackDomain?: str
|
|
|
72
72
|
declare const toRfc9457ErrorPayload: <TError = unknown>(error: HttpErrorShape) => Rfc9457ErrorPayload<TError>;
|
|
73
73
|
declare const toRfc9457ValidationErrorPayload: (error: HttpErrorShape) => Rfc9457ErrorPayload<Rfc9457ValidationError>;
|
|
74
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Base typed HTTP error with a numeric `statusCode` and machine-readable metadata.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* throw new HttpError(503, 'please try again later');
|
|
80
|
+
*/
|
|
75
81
|
declare class HttpError extends Error {
|
|
76
82
|
readonly statusCode: number;
|
|
77
83
|
readonly status: string;
|
package/index.d.ts
CHANGED
|
@@ -72,6 +72,12 @@ declare const toAip193ErrorPayload: (error: HttpErrorShape, fallbackDomain?: str
|
|
|
72
72
|
declare const toRfc9457ErrorPayload: <TError = unknown>(error: HttpErrorShape) => Rfc9457ErrorPayload<TError>;
|
|
73
73
|
declare const toRfc9457ValidationErrorPayload: (error: HttpErrorShape) => Rfc9457ErrorPayload<Rfc9457ValidationError>;
|
|
74
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Base typed HTTP error with a numeric `statusCode` and machine-readable metadata.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* throw new HttpError(503, 'please try again later');
|
|
80
|
+
*/
|
|
75
81
|
declare class HttpError extends Error {
|
|
76
82
|
readonly statusCode: number;
|
|
77
83
|
readonly status: string;
|
package/package.json
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@web-ts-toolkit/http-errors",
|
|
3
|
-
"description": "HTTP error classes for backend APIs",
|
|
4
|
-
"
|
|
3
|
+
"description": "Typed HTTP error classes and payload helpers for backend APIs",
|
|
4
|
+
"homepage": "https://web-ts-toolkit.pages.dev/docs/packages/http-errors",
|
|
5
|
+
"version": "0.6.0",
|
|
6
|
+
"sideEffects": false,
|
|
5
7
|
"keywords": [
|
|
6
8
|
"http-errors",
|
|
7
|
-
"api-errors"
|
|
9
|
+
"api-errors",
|
|
10
|
+
"problem-details",
|
|
11
|
+
"rfc9457",
|
|
12
|
+
"aip193"
|
|
8
13
|
],
|
|
9
14
|
"main": "./index.js",
|
|
10
15
|
"module": "./index.mjs",
|
|
@@ -17,16 +22,16 @@
|
|
|
17
22
|
"default": "./index.js"
|
|
18
23
|
}
|
|
19
24
|
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=20"
|
|
27
|
+
},
|
|
20
28
|
"dependencies": {
|
|
21
|
-
"@web-ts-toolkit/utils": "0.
|
|
29
|
+
"@web-ts-toolkit/utils": "0.6.0"
|
|
22
30
|
},
|
|
23
31
|
"author": "Junmin Ahn",
|
|
24
32
|
"bugs": {
|
|
25
33
|
"url": "https://github.com/egose/web-ts-toolkit/issues"
|
|
26
34
|
},
|
|
27
|
-
"engines": {
|
|
28
|
-
"node": ">=20"
|
|
29
|
-
},
|
|
30
35
|
"license": "Apache-2.0",
|
|
31
36
|
"repository": {
|
|
32
37
|
"type": "git",
|