@constructive-io/http-errors 0.2.12

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Constructive <developers@constructive.io>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # @constructive-io/http-errors
2
+
3
+ <p align="center">
4
+ <img src="https://raw.githubusercontent.com/constructive-io/constructive/refs/heads/main/assets/outline-logo.svg" height="250"><br />
5
+ @constructive-io/http-errors
6
+ <br />
7
+ <a href="https://github.com/constructive-io/dev-utils/actions/workflows/ci.yml">
8
+ <img height="20" src="https://github.com/constructive-io/dev-utils/actions/workflows/ci.yml/badge.svg" />
9
+ </a>
10
+ <a href="https://github.com/constructive-io/dev-utils/blob/main/LICENSE">
11
+ <img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/>
12
+ </a>
13
+ </p>
14
+
15
+ ## install
16
+
17
+ ```sh
18
+ npm install @constructive-io/http-errors
19
+ ```
20
+
21
+ ---
22
+
23
+ ## Development
24
+
25
+ ### Setup
26
+
27
+ 1. Clone the repository:
28
+
29
+ ```bash
30
+ git clone https://github.com/constructive-io/dev-utils.git
31
+ ```
32
+
33
+ 2. Install dependencies:
34
+
35
+ ```bash
36
+ cd dev-utils
37
+ pnpm install
38
+ pnpm build
39
+ ```
40
+
41
+ 3. Test the package of interest:
42
+
43
+ ```bash
44
+ cd packages/<packagename>
45
+ pnpm test:watch
46
+ ```
47
+
48
+ ## Credits
49
+
50
+ Built for developers, with developers.
51
+ 👉 https://launchql.com | https://hyperweb.io
52
+
53
+ ## Disclaimer
54
+
55
+ AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
56
+
57
+ No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
package/esm/index.js ADDED
@@ -0,0 +1,169 @@
1
+ export class HTTPError extends Error {
2
+ status;
3
+ constructor(message, status) {
4
+ super(`${message} | Status: ${status}`);
5
+ this.status = status;
6
+ this.name = this.constructor.name;
7
+ }
8
+ }
9
+ export class BadRequestError extends HTTPError {
10
+ constructor() { super('Bad Request', 400); }
11
+ }
12
+ export class UnauthorizedError extends HTTPError {
13
+ constructor() { super('Unauthorized', 401); }
14
+ }
15
+ export class PaymentRequiredError extends HTTPError {
16
+ constructor() { super('Payment Required', 402); }
17
+ }
18
+ export class ForbiddenError extends HTTPError {
19
+ constructor() { super('Forbidden', 403); }
20
+ }
21
+ export class NotFoundError extends HTTPError {
22
+ constructor() { super('Not Found', 404); }
23
+ }
24
+ export class MethodNotAllowedError extends HTTPError {
25
+ constructor() { super('Method Not Allowed', 405); }
26
+ }
27
+ export class NotAcceptableError extends HTTPError {
28
+ constructor() { super('Not Acceptable', 406); }
29
+ }
30
+ export class ProxyAuthenticationRequiredError extends HTTPError {
31
+ constructor() { super('Proxy Authentication Required', 407); }
32
+ }
33
+ export class RequestTimeoutError extends HTTPError {
34
+ constructor() { super('Request Timeout', 408); }
35
+ }
36
+ export class ConflictError extends HTTPError {
37
+ constructor() { super('Conflict', 409); }
38
+ }
39
+ export class GoneError extends HTTPError {
40
+ constructor() { super('Gone', 410); }
41
+ }
42
+ export class LengthRequiredError extends HTTPError {
43
+ constructor() { super('Length Required', 411); }
44
+ }
45
+ export class PreconditionFailedError extends HTTPError {
46
+ constructor() { super('Precondition Failed', 412); }
47
+ }
48
+ export class PayloadTooLargeError extends HTTPError {
49
+ constructor() { super('Payload Too Large', 413); }
50
+ }
51
+ export class URITooLongError extends HTTPError {
52
+ constructor() { super('URI Too Long', 414); }
53
+ }
54
+ export class UnsupportedMediaTypeError extends HTTPError {
55
+ constructor() { super('Unsupported Media Type', 415); }
56
+ }
57
+ export class RangeNotSatisfiableError extends HTTPError {
58
+ constructor() { super('Range Not Satisfiable', 416); }
59
+ }
60
+ export class ExpectationFailedError extends HTTPError {
61
+ constructor() { super('Expectation Failed', 417); }
62
+ }
63
+ export class ImATeapotError extends HTTPError {
64
+ constructor() { super('I\'m a Teapot', 418); }
65
+ }
66
+ export class MisdirectedRequestError extends HTTPError {
67
+ constructor() { super('Misdirected Request', 421); }
68
+ }
69
+ export class UnprocessableEntityError extends HTTPError {
70
+ constructor() { super('Unprocessable Entity', 422); }
71
+ }
72
+ export class LockedError extends HTTPError {
73
+ constructor() { super('Locked', 423); }
74
+ }
75
+ export class FailedDependencyError extends HTTPError {
76
+ constructor() { super('Failed Dependency', 424); }
77
+ }
78
+ export class UpgradeRequiredError extends HTTPError {
79
+ constructor() { super('Upgrade Required', 426); }
80
+ }
81
+ export class PreconditionRequiredError extends HTTPError {
82
+ constructor() { super('Precondition Required', 428); }
83
+ }
84
+ export class TooManyRequestsError extends HTTPError {
85
+ constructor() { super('Too Many Requests', 429); }
86
+ }
87
+ export class RequestHeaderFieldsTooLargeError extends HTTPError {
88
+ constructor() { super('Request Header Fields Too Large', 431); }
89
+ }
90
+ export class UnavailableForLegalReasonsError extends HTTPError {
91
+ constructor() { super('Unavailable For Legal Reasons', 451); }
92
+ }
93
+ export class InternalServerError extends HTTPError {
94
+ constructor() { super('Internal Server Error', 500); }
95
+ }
96
+ export class NotImplementedError extends HTTPError {
97
+ constructor() { super('Not Implemented', 501); }
98
+ }
99
+ export class BadGatewayError extends HTTPError {
100
+ constructor() { super('Bad Gateway', 502); }
101
+ }
102
+ export class ServiceUnavailableError extends HTTPError {
103
+ constructor() { super('Service Unavailable', 503); }
104
+ }
105
+ export class GatewayTimeoutError extends HTTPError {
106
+ constructor() { super('Gateway Timeout', 504); }
107
+ }
108
+ export class HTTPVersionNotSupportedError extends HTTPError {
109
+ constructor() { super('HTTP Version Not Supported', 505); }
110
+ }
111
+ export class VariantAlsoNegotiatesError extends HTTPError {
112
+ constructor() { super('Variant Also Negotiates', 506); }
113
+ }
114
+ export class InsufficientStorageError extends HTTPError {
115
+ constructor() { super('Insufficient Storage', 507); }
116
+ }
117
+ export class LoopDetectedError extends HTTPError {
118
+ constructor() { super('Loop Detected', 508); }
119
+ }
120
+ export class NotExtendedError extends HTTPError {
121
+ constructor() { super('Not Extended', 510); }
122
+ }
123
+ export class NetworkAuthenticationRequiredError extends HTTPError {
124
+ constructor() { super('Network Authentication Required', 511); }
125
+ }
126
+ export function createHTTPError(status) {
127
+ switch (status) {
128
+ case 400: return new BadRequestError();
129
+ case 401: return new UnauthorizedError();
130
+ case 402: return new PaymentRequiredError();
131
+ case 403: return new ForbiddenError();
132
+ case 404: return new NotFoundError();
133
+ case 405: return new MethodNotAllowedError();
134
+ case 406: return new NotAcceptableError();
135
+ case 407: return new ProxyAuthenticationRequiredError();
136
+ case 408: return new RequestTimeoutError();
137
+ case 409: return new ConflictError();
138
+ case 410: return new GoneError();
139
+ case 411: return new LengthRequiredError();
140
+ case 412: return new PreconditionFailedError();
141
+ case 413: return new PayloadTooLargeError();
142
+ case 414: return new URITooLongError();
143
+ case 415: return new UnsupportedMediaTypeError();
144
+ case 416: return new RangeNotSatisfiableError();
145
+ case 417: return new ExpectationFailedError();
146
+ case 418: return new ImATeapotError();
147
+ case 421: return new MisdirectedRequestError();
148
+ case 422: return new UnprocessableEntityError();
149
+ case 423: return new LockedError();
150
+ case 424: return new FailedDependencyError();
151
+ case 426: return new UpgradeRequiredError();
152
+ case 428: return new PreconditionRequiredError();
153
+ case 429: return new TooManyRequestsError();
154
+ case 431: return new RequestHeaderFieldsTooLargeError();
155
+ case 451: return new UnavailableForLegalReasonsError();
156
+ case 500: return new InternalServerError();
157
+ case 501: return new NotImplementedError();
158
+ case 502: return new BadGatewayError();
159
+ case 503: return new ServiceUnavailableError();
160
+ case 504: return new GatewayTimeoutError();
161
+ case 505: return new HTTPVersionNotSupportedError();
162
+ case 506: return new VariantAlsoNegotiatesError();
163
+ case 507: return new InsufficientStorageError();
164
+ case 508: return new LoopDetectedError();
165
+ case 510: return new NotExtendedError();
166
+ case 511: return new NetworkAuthenticationRequiredError();
167
+ default: return new HTTPError('Unknown Error', status);
168
+ }
169
+ }
package/index.d.ts ADDED
@@ -0,0 +1,122 @@
1
+ export declare class HTTPError extends Error {
2
+ status: number;
3
+ constructor(message: string, status: number);
4
+ }
5
+ export declare class BadRequestError extends HTTPError {
6
+ constructor();
7
+ }
8
+ export declare class UnauthorizedError extends HTTPError {
9
+ constructor();
10
+ }
11
+ export declare class PaymentRequiredError extends HTTPError {
12
+ constructor();
13
+ }
14
+ export declare class ForbiddenError extends HTTPError {
15
+ constructor();
16
+ }
17
+ export declare class NotFoundError extends HTTPError {
18
+ constructor();
19
+ }
20
+ export declare class MethodNotAllowedError extends HTTPError {
21
+ constructor();
22
+ }
23
+ export declare class NotAcceptableError extends HTTPError {
24
+ constructor();
25
+ }
26
+ export declare class ProxyAuthenticationRequiredError extends HTTPError {
27
+ constructor();
28
+ }
29
+ export declare class RequestTimeoutError extends HTTPError {
30
+ constructor();
31
+ }
32
+ export declare class ConflictError extends HTTPError {
33
+ constructor();
34
+ }
35
+ export declare class GoneError extends HTTPError {
36
+ constructor();
37
+ }
38
+ export declare class LengthRequiredError extends HTTPError {
39
+ constructor();
40
+ }
41
+ export declare class PreconditionFailedError extends HTTPError {
42
+ constructor();
43
+ }
44
+ export declare class PayloadTooLargeError extends HTTPError {
45
+ constructor();
46
+ }
47
+ export declare class URITooLongError extends HTTPError {
48
+ constructor();
49
+ }
50
+ export declare class UnsupportedMediaTypeError extends HTTPError {
51
+ constructor();
52
+ }
53
+ export declare class RangeNotSatisfiableError extends HTTPError {
54
+ constructor();
55
+ }
56
+ export declare class ExpectationFailedError extends HTTPError {
57
+ constructor();
58
+ }
59
+ export declare class ImATeapotError extends HTTPError {
60
+ constructor();
61
+ }
62
+ export declare class MisdirectedRequestError extends HTTPError {
63
+ constructor();
64
+ }
65
+ export declare class UnprocessableEntityError extends HTTPError {
66
+ constructor();
67
+ }
68
+ export declare class LockedError extends HTTPError {
69
+ constructor();
70
+ }
71
+ export declare class FailedDependencyError extends HTTPError {
72
+ constructor();
73
+ }
74
+ export declare class UpgradeRequiredError extends HTTPError {
75
+ constructor();
76
+ }
77
+ export declare class PreconditionRequiredError extends HTTPError {
78
+ constructor();
79
+ }
80
+ export declare class TooManyRequestsError extends HTTPError {
81
+ constructor();
82
+ }
83
+ export declare class RequestHeaderFieldsTooLargeError extends HTTPError {
84
+ constructor();
85
+ }
86
+ export declare class UnavailableForLegalReasonsError extends HTTPError {
87
+ constructor();
88
+ }
89
+ export declare class InternalServerError extends HTTPError {
90
+ constructor();
91
+ }
92
+ export declare class NotImplementedError extends HTTPError {
93
+ constructor();
94
+ }
95
+ export declare class BadGatewayError extends HTTPError {
96
+ constructor();
97
+ }
98
+ export declare class ServiceUnavailableError extends HTTPError {
99
+ constructor();
100
+ }
101
+ export declare class GatewayTimeoutError extends HTTPError {
102
+ constructor();
103
+ }
104
+ export declare class HTTPVersionNotSupportedError extends HTTPError {
105
+ constructor();
106
+ }
107
+ export declare class VariantAlsoNegotiatesError extends HTTPError {
108
+ constructor();
109
+ }
110
+ export declare class InsufficientStorageError extends HTTPError {
111
+ constructor();
112
+ }
113
+ export declare class LoopDetectedError extends HTTPError {
114
+ constructor();
115
+ }
116
+ export declare class NotExtendedError extends HTTPError {
117
+ constructor();
118
+ }
119
+ export declare class NetworkAuthenticationRequiredError extends HTTPError {
120
+ constructor();
121
+ }
122
+ export declare function createHTTPError(status: number): HTTPError;
package/index.js ADDED
@@ -0,0 +1,213 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NetworkAuthenticationRequiredError = exports.NotExtendedError = exports.LoopDetectedError = exports.InsufficientStorageError = exports.VariantAlsoNegotiatesError = exports.HTTPVersionNotSupportedError = exports.GatewayTimeoutError = exports.ServiceUnavailableError = exports.BadGatewayError = exports.NotImplementedError = exports.InternalServerError = exports.UnavailableForLegalReasonsError = exports.RequestHeaderFieldsTooLargeError = exports.TooManyRequestsError = exports.PreconditionRequiredError = exports.UpgradeRequiredError = exports.FailedDependencyError = exports.LockedError = exports.UnprocessableEntityError = exports.MisdirectedRequestError = exports.ImATeapotError = exports.ExpectationFailedError = exports.RangeNotSatisfiableError = exports.UnsupportedMediaTypeError = exports.URITooLongError = exports.PayloadTooLargeError = exports.PreconditionFailedError = exports.LengthRequiredError = exports.GoneError = exports.ConflictError = exports.RequestTimeoutError = exports.ProxyAuthenticationRequiredError = exports.NotAcceptableError = exports.MethodNotAllowedError = exports.NotFoundError = exports.ForbiddenError = exports.PaymentRequiredError = exports.UnauthorizedError = exports.BadRequestError = exports.HTTPError = void 0;
4
+ exports.createHTTPError = createHTTPError;
5
+ class HTTPError extends Error {
6
+ status;
7
+ constructor(message, status) {
8
+ super(`${message} | Status: ${status}`);
9
+ this.status = status;
10
+ this.name = this.constructor.name;
11
+ }
12
+ }
13
+ exports.HTTPError = HTTPError;
14
+ class BadRequestError extends HTTPError {
15
+ constructor() { super('Bad Request', 400); }
16
+ }
17
+ exports.BadRequestError = BadRequestError;
18
+ class UnauthorizedError extends HTTPError {
19
+ constructor() { super('Unauthorized', 401); }
20
+ }
21
+ exports.UnauthorizedError = UnauthorizedError;
22
+ class PaymentRequiredError extends HTTPError {
23
+ constructor() { super('Payment Required', 402); }
24
+ }
25
+ exports.PaymentRequiredError = PaymentRequiredError;
26
+ class ForbiddenError extends HTTPError {
27
+ constructor() { super('Forbidden', 403); }
28
+ }
29
+ exports.ForbiddenError = ForbiddenError;
30
+ class NotFoundError extends HTTPError {
31
+ constructor() { super('Not Found', 404); }
32
+ }
33
+ exports.NotFoundError = NotFoundError;
34
+ class MethodNotAllowedError extends HTTPError {
35
+ constructor() { super('Method Not Allowed', 405); }
36
+ }
37
+ exports.MethodNotAllowedError = MethodNotAllowedError;
38
+ class NotAcceptableError extends HTTPError {
39
+ constructor() { super('Not Acceptable', 406); }
40
+ }
41
+ exports.NotAcceptableError = NotAcceptableError;
42
+ class ProxyAuthenticationRequiredError extends HTTPError {
43
+ constructor() { super('Proxy Authentication Required', 407); }
44
+ }
45
+ exports.ProxyAuthenticationRequiredError = ProxyAuthenticationRequiredError;
46
+ class RequestTimeoutError extends HTTPError {
47
+ constructor() { super('Request Timeout', 408); }
48
+ }
49
+ exports.RequestTimeoutError = RequestTimeoutError;
50
+ class ConflictError extends HTTPError {
51
+ constructor() { super('Conflict', 409); }
52
+ }
53
+ exports.ConflictError = ConflictError;
54
+ class GoneError extends HTTPError {
55
+ constructor() { super('Gone', 410); }
56
+ }
57
+ exports.GoneError = GoneError;
58
+ class LengthRequiredError extends HTTPError {
59
+ constructor() { super('Length Required', 411); }
60
+ }
61
+ exports.LengthRequiredError = LengthRequiredError;
62
+ class PreconditionFailedError extends HTTPError {
63
+ constructor() { super('Precondition Failed', 412); }
64
+ }
65
+ exports.PreconditionFailedError = PreconditionFailedError;
66
+ class PayloadTooLargeError extends HTTPError {
67
+ constructor() { super('Payload Too Large', 413); }
68
+ }
69
+ exports.PayloadTooLargeError = PayloadTooLargeError;
70
+ class URITooLongError extends HTTPError {
71
+ constructor() { super('URI Too Long', 414); }
72
+ }
73
+ exports.URITooLongError = URITooLongError;
74
+ class UnsupportedMediaTypeError extends HTTPError {
75
+ constructor() { super('Unsupported Media Type', 415); }
76
+ }
77
+ exports.UnsupportedMediaTypeError = UnsupportedMediaTypeError;
78
+ class RangeNotSatisfiableError extends HTTPError {
79
+ constructor() { super('Range Not Satisfiable', 416); }
80
+ }
81
+ exports.RangeNotSatisfiableError = RangeNotSatisfiableError;
82
+ class ExpectationFailedError extends HTTPError {
83
+ constructor() { super('Expectation Failed', 417); }
84
+ }
85
+ exports.ExpectationFailedError = ExpectationFailedError;
86
+ class ImATeapotError extends HTTPError {
87
+ constructor() { super('I\'m a Teapot', 418); }
88
+ }
89
+ exports.ImATeapotError = ImATeapotError;
90
+ class MisdirectedRequestError extends HTTPError {
91
+ constructor() { super('Misdirected Request', 421); }
92
+ }
93
+ exports.MisdirectedRequestError = MisdirectedRequestError;
94
+ class UnprocessableEntityError extends HTTPError {
95
+ constructor() { super('Unprocessable Entity', 422); }
96
+ }
97
+ exports.UnprocessableEntityError = UnprocessableEntityError;
98
+ class LockedError extends HTTPError {
99
+ constructor() { super('Locked', 423); }
100
+ }
101
+ exports.LockedError = LockedError;
102
+ class FailedDependencyError extends HTTPError {
103
+ constructor() { super('Failed Dependency', 424); }
104
+ }
105
+ exports.FailedDependencyError = FailedDependencyError;
106
+ class UpgradeRequiredError extends HTTPError {
107
+ constructor() { super('Upgrade Required', 426); }
108
+ }
109
+ exports.UpgradeRequiredError = UpgradeRequiredError;
110
+ class PreconditionRequiredError extends HTTPError {
111
+ constructor() { super('Precondition Required', 428); }
112
+ }
113
+ exports.PreconditionRequiredError = PreconditionRequiredError;
114
+ class TooManyRequestsError extends HTTPError {
115
+ constructor() { super('Too Many Requests', 429); }
116
+ }
117
+ exports.TooManyRequestsError = TooManyRequestsError;
118
+ class RequestHeaderFieldsTooLargeError extends HTTPError {
119
+ constructor() { super('Request Header Fields Too Large', 431); }
120
+ }
121
+ exports.RequestHeaderFieldsTooLargeError = RequestHeaderFieldsTooLargeError;
122
+ class UnavailableForLegalReasonsError extends HTTPError {
123
+ constructor() { super('Unavailable For Legal Reasons', 451); }
124
+ }
125
+ exports.UnavailableForLegalReasonsError = UnavailableForLegalReasonsError;
126
+ class InternalServerError extends HTTPError {
127
+ constructor() { super('Internal Server Error', 500); }
128
+ }
129
+ exports.InternalServerError = InternalServerError;
130
+ class NotImplementedError extends HTTPError {
131
+ constructor() { super('Not Implemented', 501); }
132
+ }
133
+ exports.NotImplementedError = NotImplementedError;
134
+ class BadGatewayError extends HTTPError {
135
+ constructor() { super('Bad Gateway', 502); }
136
+ }
137
+ exports.BadGatewayError = BadGatewayError;
138
+ class ServiceUnavailableError extends HTTPError {
139
+ constructor() { super('Service Unavailable', 503); }
140
+ }
141
+ exports.ServiceUnavailableError = ServiceUnavailableError;
142
+ class GatewayTimeoutError extends HTTPError {
143
+ constructor() { super('Gateway Timeout', 504); }
144
+ }
145
+ exports.GatewayTimeoutError = GatewayTimeoutError;
146
+ class HTTPVersionNotSupportedError extends HTTPError {
147
+ constructor() { super('HTTP Version Not Supported', 505); }
148
+ }
149
+ exports.HTTPVersionNotSupportedError = HTTPVersionNotSupportedError;
150
+ class VariantAlsoNegotiatesError extends HTTPError {
151
+ constructor() { super('Variant Also Negotiates', 506); }
152
+ }
153
+ exports.VariantAlsoNegotiatesError = VariantAlsoNegotiatesError;
154
+ class InsufficientStorageError extends HTTPError {
155
+ constructor() { super('Insufficient Storage', 507); }
156
+ }
157
+ exports.InsufficientStorageError = InsufficientStorageError;
158
+ class LoopDetectedError extends HTTPError {
159
+ constructor() { super('Loop Detected', 508); }
160
+ }
161
+ exports.LoopDetectedError = LoopDetectedError;
162
+ class NotExtendedError extends HTTPError {
163
+ constructor() { super('Not Extended', 510); }
164
+ }
165
+ exports.NotExtendedError = NotExtendedError;
166
+ class NetworkAuthenticationRequiredError extends HTTPError {
167
+ constructor() { super('Network Authentication Required', 511); }
168
+ }
169
+ exports.NetworkAuthenticationRequiredError = NetworkAuthenticationRequiredError;
170
+ function createHTTPError(status) {
171
+ switch (status) {
172
+ case 400: return new BadRequestError();
173
+ case 401: return new UnauthorizedError();
174
+ case 402: return new PaymentRequiredError();
175
+ case 403: return new ForbiddenError();
176
+ case 404: return new NotFoundError();
177
+ case 405: return new MethodNotAllowedError();
178
+ case 406: return new NotAcceptableError();
179
+ case 407: return new ProxyAuthenticationRequiredError();
180
+ case 408: return new RequestTimeoutError();
181
+ case 409: return new ConflictError();
182
+ case 410: return new GoneError();
183
+ case 411: return new LengthRequiredError();
184
+ case 412: return new PreconditionFailedError();
185
+ case 413: return new PayloadTooLargeError();
186
+ case 414: return new URITooLongError();
187
+ case 415: return new UnsupportedMediaTypeError();
188
+ case 416: return new RangeNotSatisfiableError();
189
+ case 417: return new ExpectationFailedError();
190
+ case 418: return new ImATeapotError();
191
+ case 421: return new MisdirectedRequestError();
192
+ case 422: return new UnprocessableEntityError();
193
+ case 423: return new LockedError();
194
+ case 424: return new FailedDependencyError();
195
+ case 426: return new UpgradeRequiredError();
196
+ case 428: return new PreconditionRequiredError();
197
+ case 429: return new TooManyRequestsError();
198
+ case 431: return new RequestHeaderFieldsTooLargeError();
199
+ case 451: return new UnavailableForLegalReasonsError();
200
+ case 500: return new InternalServerError();
201
+ case 501: return new NotImplementedError();
202
+ case 502: return new BadGatewayError();
203
+ case 503: return new ServiceUnavailableError();
204
+ case 504: return new GatewayTimeoutError();
205
+ case 505: return new HTTPVersionNotSupportedError();
206
+ case 506: return new VariantAlsoNegotiatesError();
207
+ case 507: return new InsufficientStorageError();
208
+ case 508: return new LoopDetectedError();
209
+ case 510: return new NotExtendedError();
210
+ case 511: return new NetworkAuthenticationRequiredError();
211
+ default: return new HTTPError('Unknown Error', status);
212
+ }
213
+ }
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@constructive-io/http-errors",
3
+ "version": "0.2.12",
4
+ "author": "Constructive <developers@constructive.io>",
5
+ "description": "HTTP error handling utilities for API clients",
6
+ "main": "index.js",
7
+ "module": "esm/index.js",
8
+ "types": "index.d.ts",
9
+ "homepage": "https://github.com/constructive-io/dev-utils",
10
+ "license": "MIT",
11
+ "publishConfig": {
12
+ "access": "public",
13
+ "directory": "dist"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/constructive-io/dev-utils"
18
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/constructive-io/dev-utils/issues"
21
+ },
22
+ "scripts": {
23
+ "copy": "makage assets",
24
+ "clean": "makage clean",
25
+ "prepublishOnly": "npm run build",
26
+ "build": "makage build",
27
+ "lint": "eslint . --fix",
28
+ "test": "jest",
29
+ "test:watch": "jest --watch"
30
+ },
31
+ "devDependencies": {
32
+ "makage": "0.1.8"
33
+ },
34
+ "keywords": [],
35
+ "gitHead": "c5a1d1d1440805103acfb584c4c97c78eeaa50e9"
36
+ }