sleepy-serv 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 +38 -47
- package/package.json +8 -9
- package/src/errors.js +53 -41
- package/src/index.js +176 -101
- package/src/messages.js +164 -0
- package/src/middleware.js +83 -61
- package/src/socket.js +542 -0
- package/src/utils.js +49 -0
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `sleepy-serv`
|
|
2
2
|
|
|
3
3
|
A directory-driven web server designed for REST-ful applications
|
|
4
4
|
|
|
@@ -86,9 +86,9 @@ These functions take three parameters:
|
|
|
86
86
|
- `res`: a results object
|
|
87
87
|
- `next`: a function to call the next middleware in the chain (or `null` for the final handler)
|
|
88
88
|
|
|
89
|
-
The `res` parameter might seem familiar if coming from ExpressJS, but this parameter has a different purpose. The `res` parameter is
|
|
89
|
+
The `res` parameter might seem familiar if coming from ExpressJS, but this parameter has a different purpose. The `res` parameter is the "result" value handed to the current middleware. Middleware do not mutate it. Instead, whatever a middleware passes into `next(data)` becomes the `res` value the next middleware receives. This way, the `req` object stays as a lean `BunRequest`, and each middleware decides exactly what the next one sees.
|
|
90
90
|
|
|
91
|
-
The `next` parameter is a function that
|
|
91
|
+
The `next` parameter is a function that advances the chain. Whatever you pass to it becomes the next middleware's `res`. Calling `next()` with no argument sets the next `res` to `undefined`, so to forward the current result unchanged, return `next(res)`. For route handlers (the final function in the chain), `next` will be `null`.
|
|
92
92
|
|
|
93
93
|
These handlers can also be `async` functions and `sleepy-serv` will wait for them to finish before moving on.
|
|
94
94
|
|
|
@@ -99,11 +99,11 @@ As mentioned earlier, method definition files can also export an array of functi
|
|
|
99
99
|
```js
|
|
100
100
|
export default [
|
|
101
101
|
async (req, res, next) => {
|
|
102
|
-
res
|
|
103
|
-
return next()
|
|
102
|
+
/* transform `res` into the parsed body for the next middleware */
|
|
103
|
+
return next(await req.json())
|
|
104
104
|
},
|
|
105
105
|
(req, res) => { /* notice that the last function doesn't take `next` */
|
|
106
|
-
console.log('JSON body:', res
|
|
106
|
+
console.log('JSON body:', res)
|
|
107
107
|
|
|
108
108
|
return new Response('Hello world')
|
|
109
109
|
},
|
|
@@ -115,7 +115,7 @@ This is useful if you want to break common logic up into reusable functions. The
|
|
|
115
115
|
#### Middleware Chain Behavior
|
|
116
116
|
|
|
117
117
|
Each middleware function must do one of the following:
|
|
118
|
-
- **Call `next()`**: Continue to the next middleware
|
|
118
|
+
- **Call `next(data)`**: Continue to the next middleware by returning `next(data)`, where `data` becomes that middleware's `res`. To forward the current result unchanged, return `next(res)`
|
|
119
119
|
- **Return a Response**: End the chain (early) by returning a `BunResponse` object
|
|
120
120
|
- **Throw an error**: Stop the chain and trigger error handling
|
|
121
121
|
|
|
@@ -137,12 +137,13 @@ export default [
|
|
|
137
137
|
(req, res, next) => {
|
|
138
138
|
console.log('2nd middleware')
|
|
139
139
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
140
|
+
return next({ // continue to route handler
|
|
141
|
+
...res,
|
|
142
|
+
user: {
|
|
143
|
+
id: 123,
|
|
144
|
+
name: 'John',
|
|
145
|
+
},
|
|
146
|
+
})
|
|
146
147
|
},
|
|
147
148
|
(req, res) => {
|
|
148
149
|
console.log('Final, "route" handler')
|
|
@@ -159,7 +160,7 @@ Middleware functions are executed in the following order:
|
|
|
159
160
|
2. **Directory-level middleware** (from `meta.js` files, from root to leaf)
|
|
160
161
|
3. **Route-level middleware** (defined in the route file array)
|
|
161
162
|
|
|
162
|
-
Each middleware function receives the same `req`
|
|
163
|
+
Each middleware function receives the same `req` object. The `res` value, by contrast, is whatever the previous middleware passed into `next(data)`, allowing data to be transformed or accumulated as it flows through the chain.
|
|
163
164
|
|
|
164
165
|
#### Breaking the Middleware Chain - Responses
|
|
165
166
|
|
|
@@ -233,7 +234,7 @@ It's also possible for resource directories to contain a `meta.js` file. These f
|
|
|
233
234
|
export const middleware = [
|
|
234
235
|
(req, res, next) => {
|
|
235
236
|
/* do middleware things */
|
|
236
|
-
return next() // Continue to next middleware
|
|
237
|
+
return next(res) // Continue to next middleware, forwarding `res`
|
|
237
238
|
},
|
|
238
239
|
]
|
|
239
240
|
```
|
|
@@ -290,43 +291,45 @@ At the time of this writing, `meta.js` only exports middleware functions, but it
|
|
|
290
291
|
|
|
291
292
|
`sleepy-serv` also comes built-in with a few useful middleware functions that are commonly used.
|
|
292
293
|
|
|
293
|
-
###
|
|
294
|
+
### parseJsonBody()
|
|
294
295
|
|
|
295
|
-
This middleware parses the request's
|
|
296
|
+
This function returns a middleware that parses the request's body as a JSON string and forwards the parsed value as the next middleware's `res` via `next(body)`. The returned middleware throws a `BadRequestError` if parsing fails, and forwards `res` unchanged (`next(res)`) when there is no `content-type`. Additional body parsers can be written in the future to accommodate other body encoding schemes (such as XML or protobuf).
|
|
296
297
|
|
|
297
298
|
Example usage:
|
|
298
299
|
|
|
299
300
|
```js
|
|
300
|
-
import {
|
|
301
|
+
import { parseJsonBody } from 'sleepy-serv'
|
|
301
302
|
|
|
302
303
|
export default [
|
|
303
|
-
|
|
304
|
+
parseJsonBody(),
|
|
304
305
|
(req, res) => {
|
|
305
|
-
console.log('Parsed JSON:', res
|
|
306
|
+
console.log('Parsed JSON:', res)
|
|
306
307
|
|
|
307
308
|
return new Response('JSON received')
|
|
308
309
|
},
|
|
309
310
|
]
|
|
310
311
|
```
|
|
311
312
|
|
|
312
|
-
###
|
|
313
|
+
### validateSchemas(schemas)
|
|
313
314
|
|
|
314
|
-
This function returns a middleware function that validates request data against provided schemas. The returned middleware function has the signature `(req, res, next)` and
|
|
315
|
+
This function returns a middleware function that validates request data against provided schemas. The returned middleware function has the signature `(req, res, next)` and forwards `res` via `next(res)` after successful validation.
|
|
315
316
|
|
|
316
317
|
The `schemas` object can contain these optional properties:
|
|
317
318
|
- `headers`: takes a string formatter schema to evaluate `req.headers`
|
|
318
319
|
- `params`: takes a string formatter schema to evaluate `req.params`
|
|
319
320
|
- `query`: takes a string formatter schema to evaluate `req.query`
|
|
320
|
-
- `body`: takes a JSON validation schema to evaluate `res
|
|
321
|
+
- `body`: takes a JSON validation schema to evaluate `res` (the body value passed in via `next`)
|
|
322
|
+
|
|
323
|
+
Only the keys you pass are validated. Any key you omit is skipped entirely, and `res` is forwarded unchanged via `next(res)`; there is no implicit default schema for a missing `body`.
|
|
321
324
|
|
|
322
325
|
Example usage:
|
|
323
326
|
|
|
324
327
|
```js
|
|
325
|
-
import {
|
|
328
|
+
import { parseJsonBody, validateSchemas } from 'sleepy-serv'
|
|
326
329
|
|
|
327
330
|
export default [
|
|
328
|
-
|
|
329
|
-
|
|
331
|
+
parseJsonBody(),
|
|
332
|
+
validateSchemas({
|
|
330
333
|
params: {
|
|
331
334
|
userId: { type: 'format', value: 'uuid' }
|
|
332
335
|
},
|
|
@@ -363,7 +366,7 @@ PUT /contacts/123/addresses
|
|
|
363
366
|
***
|
|
364
367
|
TODO: add JSON schema example.
|
|
365
368
|
|
|
366
|
-
Please take a look at the `
|
|
369
|
+
Please take a look at the `packages/server/src/middleware.test.js` test file for a far a comprehensive set of examples on how to use this middleware.
|
|
367
370
|
***
|
|
368
371
|
|
|
369
372
|
The `headers`, `params`, and `query` (querystrings) can only be strings, so they're evaulated using a simplified _string format schema_ instead of a full JSON schema.
|
|
@@ -388,13 +391,15 @@ This determines how to evaulate the string based on the `type` parameter. If `ty
|
|
|
388
391
|
Custom formats can also be provided by using the `setValidationFormats()` during app initialization. Here's an example:
|
|
389
392
|
|
|
390
393
|
```javascript
|
|
391
|
-
|
|
394
|
+
import { setValidationFormats } from 'sleepy-serv'
|
|
395
|
+
|
|
396
|
+
setValidationFormats({
|
|
392
397
|
phone: /^\d{10}$/, /* 10-digit, numeric string */
|
|
393
398
|
postalCode: /^\d{5}$/, /* 5-digit, numeric string */
|
|
394
399
|
})
|
|
395
400
|
```
|
|
396
401
|
|
|
397
|
-
Calling `setValidationFormats()` extends the possible values that can be passed to the `value` property when evaulating strings in either the string formatter schema, or the
|
|
402
|
+
Calling `setValidationFormats()` extends the possible values that can be passed to the `value` property when evaulating strings in either the string formatter schema, or the body's JSON schema.
|
|
398
403
|
|
|
399
404
|
## `createApp()` Options
|
|
400
405
|
|
|
@@ -403,11 +408,11 @@ Calling `setValidationFormats()` extends the possible values that can be passed
|
|
|
403
408
|
You can define app-level middleware that will be applied to all routes:
|
|
404
409
|
|
|
405
410
|
```js
|
|
406
|
-
import {
|
|
411
|
+
import { parseJsonBody } from 'sleepy-serv'
|
|
407
412
|
|
|
408
413
|
const app = await createApp(PORT, import.meta.dirname, {
|
|
409
414
|
middleware: [
|
|
410
|
-
|
|
415
|
+
parseJsonBody(),
|
|
411
416
|
(req, res, next) => {
|
|
412
417
|
console.log(`${req.method} ${req.url}`)
|
|
413
418
|
return next()
|
|
@@ -418,6 +423,8 @@ const app = await createApp(PORT, import.meta.dirname, {
|
|
|
418
423
|
|
|
419
424
|
App-level middleware is executed before any directory-level or route-level middleware.
|
|
420
425
|
|
|
426
|
+
Note that the reserved `/ws` handshake routes are folded into these same chains, so app-level middleware runs against them too. A catch-all validator (for example a `validateSchemas` that requires a JSON body or a specific header on every request) will therefore also run against the body-less `/ws` handshake requests and reject them. Scope such validators below the reserved paths rather than applying them app-wide.
|
|
427
|
+
|
|
421
428
|
### `hostname`
|
|
422
429
|
|
|
423
430
|
The hostname can be customized like so:
|
|
@@ -465,19 +472,3 @@ const app = await createApp(PORT, import.meta.dirname, {
|
|
|
465
472
|
onClose: () => console.info('closing down...'),
|
|
466
473
|
})
|
|
467
474
|
```
|
|
468
|
-
|
|
469
|
-
## Running the Local Example App
|
|
470
|
-
|
|
471
|
-
1. Install [`bun.sh`](https://bun.sh)
|
|
472
|
-
1. Link the library package:
|
|
473
|
-
- `$ cd lib`
|
|
474
|
-
- `$ bun link`
|
|
475
|
-
1. Link the library to the project
|
|
476
|
-
- `$ cd ../example`
|
|
477
|
-
- `$ npm link sleepy-serv`
|
|
478
|
-
1. Finally, run the app: `$ bun --watch run start`
|
|
479
|
-
|
|
480
|
-
## Running Tests
|
|
481
|
-
|
|
482
|
-
- Use `bun`'s built-in test runner
|
|
483
|
-
- Run tests from the `./lib` directory
|
package/package.json
CHANGED
|
@@ -2,9 +2,14 @@
|
|
|
2
2
|
"name": "sleepy-serv",
|
|
3
3
|
"description": "A more opinionated web server for building REST-ful applications",
|
|
4
4
|
"author": "Travis J True",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.6.0",
|
|
6
6
|
"exports": "./src/index.js",
|
|
7
7
|
"type": "module",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/travistrue2008/sleepy-serv.git",
|
|
11
|
+
"directory": "packages/server"
|
|
12
|
+
},
|
|
8
13
|
"keywords": [
|
|
9
14
|
"rest",
|
|
10
15
|
"serv",
|
|
@@ -12,15 +17,9 @@
|
|
|
12
17
|
"web server",
|
|
13
18
|
"www"
|
|
14
19
|
],
|
|
15
|
-
"scripts": {
|
|
16
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
17
|
-
},
|
|
18
|
-
"devDependencies": {
|
|
19
|
-
"axios": "^1.7.9",
|
|
20
|
-
"eslint": "9.20.1"
|
|
21
|
-
},
|
|
20
|
+
"scripts": {},
|
|
22
21
|
"dependencies": {
|
|
23
|
-
"ajv": "^8.
|
|
22
|
+
"ajv": "^8.20.0",
|
|
24
23
|
"ajv-formats": "^3.0.1"
|
|
25
24
|
}
|
|
26
25
|
}
|
package/src/errors.js
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
class RequestError extends Error {
|
|
1
|
+
export class RequestError extends Error {
|
|
2
|
+
static get status () {
|
|
3
|
+
throw new Error('Unimplemented')
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
get output () {
|
|
7
|
+
return this.message ? { message: this.message } : null
|
|
8
|
+
}
|
|
9
|
+
|
|
2
10
|
constructor (message) {
|
|
3
11
|
super(message)
|
|
4
12
|
|
|
@@ -9,7 +17,7 @@ class RequestError extends Error {
|
|
|
9
17
|
// 4xx - Client Errors
|
|
10
18
|
|
|
11
19
|
export class BadRequestError extends RequestError {
|
|
12
|
-
static get
|
|
20
|
+
static get status () { return 400 }
|
|
13
21
|
|
|
14
22
|
constructor (message) {
|
|
15
23
|
super(message)
|
|
@@ -19,7 +27,7 @@ export class BadRequestError extends RequestError {
|
|
|
19
27
|
}
|
|
20
28
|
|
|
21
29
|
export class UnauthorizedError extends RequestError {
|
|
22
|
-
static get
|
|
30
|
+
static get status () { return 401 }
|
|
23
31
|
|
|
24
32
|
constructor (message) {
|
|
25
33
|
super(message)
|
|
@@ -29,7 +37,7 @@ export class UnauthorizedError extends RequestError {
|
|
|
29
37
|
}
|
|
30
38
|
|
|
31
39
|
export class PaymentRequiredError extends RequestError {
|
|
32
|
-
static get
|
|
40
|
+
static get status () { return 402 }
|
|
33
41
|
|
|
34
42
|
constructor (message) {
|
|
35
43
|
super(message)
|
|
@@ -39,7 +47,7 @@ export class PaymentRequiredError extends RequestError {
|
|
|
39
47
|
}
|
|
40
48
|
|
|
41
49
|
export class ForbiddenError extends RequestError {
|
|
42
|
-
static get
|
|
50
|
+
static get status () { return 403 }
|
|
43
51
|
|
|
44
52
|
constructor (message) {
|
|
45
53
|
super(message)
|
|
@@ -49,7 +57,7 @@ export class ForbiddenError extends RequestError {
|
|
|
49
57
|
}
|
|
50
58
|
|
|
51
59
|
export class NotFoundError extends RequestError {
|
|
52
|
-
static get
|
|
60
|
+
static get status () { return 404 }
|
|
53
61
|
|
|
54
62
|
constructor () {
|
|
55
63
|
super('')
|
|
@@ -59,7 +67,7 @@ export class NotFoundError extends RequestError {
|
|
|
59
67
|
}
|
|
60
68
|
|
|
61
69
|
export class MethodNotAllowedError extends RequestError {
|
|
62
|
-
static get
|
|
70
|
+
static get status () { return 405 }
|
|
63
71
|
|
|
64
72
|
constructor () {
|
|
65
73
|
super('')
|
|
@@ -69,7 +77,7 @@ export class MethodNotAllowedError extends RequestError {
|
|
|
69
77
|
}
|
|
70
78
|
|
|
71
79
|
export class NotAcceptableError extends RequestError {
|
|
72
|
-
static get
|
|
80
|
+
static get status () { return 406 }
|
|
73
81
|
|
|
74
82
|
constructor (message) {
|
|
75
83
|
super(message)
|
|
@@ -79,7 +87,7 @@ export class NotAcceptableError extends RequestError {
|
|
|
79
87
|
}
|
|
80
88
|
|
|
81
89
|
export class ProxyAuthenticationRequiredError extends RequestError {
|
|
82
|
-
static get
|
|
90
|
+
static get status () { return 407 }
|
|
83
91
|
|
|
84
92
|
constructor (message) {
|
|
85
93
|
super(message)
|
|
@@ -89,7 +97,7 @@ export class ProxyAuthenticationRequiredError extends RequestError {
|
|
|
89
97
|
}
|
|
90
98
|
|
|
91
99
|
export class RequestTimeoutError extends RequestError {
|
|
92
|
-
static get
|
|
100
|
+
static get status () { return 408 }
|
|
93
101
|
|
|
94
102
|
constructor (message) {
|
|
95
103
|
super(message)
|
|
@@ -99,7 +107,7 @@ export class RequestTimeoutError extends RequestError {
|
|
|
99
107
|
}
|
|
100
108
|
|
|
101
109
|
export class ConflictError extends RequestError {
|
|
102
|
-
static get
|
|
110
|
+
static get status () { return 409 }
|
|
103
111
|
|
|
104
112
|
constructor (message) {
|
|
105
113
|
super(message)
|
|
@@ -109,7 +117,7 @@ export class ConflictError extends RequestError {
|
|
|
109
117
|
}
|
|
110
118
|
|
|
111
119
|
export class GoneError extends RequestError {
|
|
112
|
-
static get
|
|
120
|
+
static get status () { return 410 }
|
|
113
121
|
|
|
114
122
|
constructor (message) {
|
|
115
123
|
super(message)
|
|
@@ -119,7 +127,7 @@ export class GoneError extends RequestError {
|
|
|
119
127
|
}
|
|
120
128
|
|
|
121
129
|
export class LengthRequiredError extends RequestError {
|
|
122
|
-
static get
|
|
130
|
+
static get status () { return 411 }
|
|
123
131
|
|
|
124
132
|
constructor (message) {
|
|
125
133
|
super(message)
|
|
@@ -129,7 +137,7 @@ export class LengthRequiredError extends RequestError {
|
|
|
129
137
|
}
|
|
130
138
|
|
|
131
139
|
export class PreconditionFailedError extends RequestError {
|
|
132
|
-
static get
|
|
140
|
+
static get status () { return 412 }
|
|
133
141
|
|
|
134
142
|
constructor (message) {
|
|
135
143
|
super(message)
|
|
@@ -139,7 +147,7 @@ export class PreconditionFailedError extends RequestError {
|
|
|
139
147
|
}
|
|
140
148
|
|
|
141
149
|
export class PayloadTooLargeError extends RequestError {
|
|
142
|
-
static get
|
|
150
|
+
static get status () { return 413 }
|
|
143
151
|
|
|
144
152
|
constructor (message) {
|
|
145
153
|
super(message)
|
|
@@ -149,7 +157,7 @@ export class PayloadTooLargeError extends RequestError {
|
|
|
149
157
|
}
|
|
150
158
|
|
|
151
159
|
export class UriTooLongError extends RequestError {
|
|
152
|
-
static get
|
|
160
|
+
static get status () { return 414 }
|
|
153
161
|
|
|
154
162
|
constructor (message) {
|
|
155
163
|
super(message)
|
|
@@ -159,7 +167,7 @@ export class UriTooLongError extends RequestError {
|
|
|
159
167
|
}
|
|
160
168
|
|
|
161
169
|
export class UnsupportedMediaTypeError extends RequestError {
|
|
162
|
-
static get
|
|
170
|
+
static get status () { return 415 }
|
|
163
171
|
|
|
164
172
|
constructor (subject) {
|
|
165
173
|
super(`Unsupported ${subject}`)
|
|
@@ -169,7 +177,7 @@ export class UnsupportedMediaTypeError extends RequestError {
|
|
|
169
177
|
}
|
|
170
178
|
|
|
171
179
|
export class RangeNotSatisfiableError extends RequestError {
|
|
172
|
-
static get
|
|
180
|
+
static get status () { return 416 }
|
|
173
181
|
|
|
174
182
|
constructor (message) {
|
|
175
183
|
super(message)
|
|
@@ -179,7 +187,7 @@ export class RangeNotSatisfiableError extends RequestError {
|
|
|
179
187
|
}
|
|
180
188
|
|
|
181
189
|
export class ExpectationFailedError extends RequestError {
|
|
182
|
-
static get
|
|
190
|
+
static get status () { return 417 }
|
|
183
191
|
|
|
184
192
|
constructor (message) {
|
|
185
193
|
super(message)
|
|
@@ -189,7 +197,7 @@ export class ExpectationFailedError extends RequestError {
|
|
|
189
197
|
}
|
|
190
198
|
|
|
191
199
|
export class ImATeapotError extends RequestError {
|
|
192
|
-
static get
|
|
200
|
+
static get status () { return 418 }
|
|
193
201
|
|
|
194
202
|
constructor (message) {
|
|
195
203
|
super(message)
|
|
@@ -199,7 +207,7 @@ export class ImATeapotError extends RequestError {
|
|
|
199
207
|
}
|
|
200
208
|
|
|
201
209
|
export class MisdirectedRequestError extends RequestError {
|
|
202
|
-
static get
|
|
210
|
+
static get status () { return 421 }
|
|
203
211
|
|
|
204
212
|
constructor (message) {
|
|
205
213
|
super(message)
|
|
@@ -209,7 +217,11 @@ export class MisdirectedRequestError extends RequestError {
|
|
|
209
217
|
}
|
|
210
218
|
|
|
211
219
|
export class UnprocessableContentError extends RequestError {
|
|
212
|
-
static get
|
|
220
|
+
static get status () { return 422 }
|
|
221
|
+
|
|
222
|
+
get output () {
|
|
223
|
+
return JSON.parse(this.message)
|
|
224
|
+
}
|
|
213
225
|
|
|
214
226
|
constructor (errors) {
|
|
215
227
|
super(JSON.stringify(errors))
|
|
@@ -219,7 +231,7 @@ export class UnprocessableContentError extends RequestError {
|
|
|
219
231
|
}
|
|
220
232
|
|
|
221
233
|
export class LockedError extends RequestError {
|
|
222
|
-
static get
|
|
234
|
+
static get status () { return 423 }
|
|
223
235
|
|
|
224
236
|
constructor (message) {
|
|
225
237
|
super(message)
|
|
@@ -229,7 +241,7 @@ export class LockedError extends RequestError {
|
|
|
229
241
|
}
|
|
230
242
|
|
|
231
243
|
export class FailedDependencyError extends RequestError {
|
|
232
|
-
static get
|
|
244
|
+
static get status () { return 424 }
|
|
233
245
|
|
|
234
246
|
constructor (message) {
|
|
235
247
|
super(message)
|
|
@@ -239,7 +251,7 @@ export class FailedDependencyError extends RequestError {
|
|
|
239
251
|
}
|
|
240
252
|
|
|
241
253
|
export class TooEarlyError extends RequestError {
|
|
242
|
-
static get
|
|
254
|
+
static get status () { return 425 }
|
|
243
255
|
|
|
244
256
|
constructor (message) {
|
|
245
257
|
super(message)
|
|
@@ -249,7 +261,7 @@ export class TooEarlyError extends RequestError {
|
|
|
249
261
|
}
|
|
250
262
|
|
|
251
263
|
export class UpgradeRequiredError extends RequestError {
|
|
252
|
-
static get
|
|
264
|
+
static get status () { return 426 }
|
|
253
265
|
|
|
254
266
|
constructor (message) {
|
|
255
267
|
super(message)
|
|
@@ -259,7 +271,7 @@ export class UpgradeRequiredError extends RequestError {
|
|
|
259
271
|
}
|
|
260
272
|
|
|
261
273
|
export class PreconditionRequiredError extends RequestError {
|
|
262
|
-
static get
|
|
274
|
+
static get status () { return 428 }
|
|
263
275
|
|
|
264
276
|
constructor (message) {
|
|
265
277
|
super(message)
|
|
@@ -269,7 +281,7 @@ export class PreconditionRequiredError extends RequestError {
|
|
|
269
281
|
}
|
|
270
282
|
|
|
271
283
|
export class TooManyRequestsError extends RequestError {
|
|
272
|
-
static get
|
|
284
|
+
static get status () { return 429 }
|
|
273
285
|
|
|
274
286
|
constructor (message) {
|
|
275
287
|
super(message)
|
|
@@ -279,7 +291,7 @@ export class TooManyRequestsError extends RequestError {
|
|
|
279
291
|
}
|
|
280
292
|
|
|
281
293
|
export class RequestHeaderFieldsTooLargeError extends RequestError {
|
|
282
|
-
static get
|
|
294
|
+
static get status () { return 431 }
|
|
283
295
|
|
|
284
296
|
constructor (message) {
|
|
285
297
|
super(message)
|
|
@@ -289,7 +301,7 @@ export class RequestHeaderFieldsTooLargeError extends RequestError {
|
|
|
289
301
|
}
|
|
290
302
|
|
|
291
303
|
export class UnavailableForLegalReasonsError extends RequestError {
|
|
292
|
-
static get
|
|
304
|
+
static get status () { return 451 }
|
|
293
305
|
|
|
294
306
|
constructor (message) {
|
|
295
307
|
super(message)
|
|
@@ -301,7 +313,7 @@ export class UnavailableForLegalReasonsError extends RequestError {
|
|
|
301
313
|
// 5xx - Server Errors
|
|
302
314
|
|
|
303
315
|
export class InternalServerError extends RequestError {
|
|
304
|
-
static get
|
|
316
|
+
static get status () { return 500 }
|
|
305
317
|
|
|
306
318
|
constructor (message, ctx) {
|
|
307
319
|
super(message)
|
|
@@ -312,7 +324,7 @@ export class InternalServerError extends RequestError {
|
|
|
312
324
|
}
|
|
313
325
|
|
|
314
326
|
export class NotImplementedError extends RequestError {
|
|
315
|
-
static get
|
|
327
|
+
static get status () { return 501 }
|
|
316
328
|
|
|
317
329
|
constructor () {
|
|
318
330
|
super('')
|
|
@@ -322,7 +334,7 @@ export class NotImplementedError extends RequestError {
|
|
|
322
334
|
}
|
|
323
335
|
|
|
324
336
|
export class BadGatewayError extends RequestError {
|
|
325
|
-
static get
|
|
337
|
+
static get status () { return 502 }
|
|
326
338
|
|
|
327
339
|
constructor (message) {
|
|
328
340
|
super(message)
|
|
@@ -332,7 +344,7 @@ export class BadGatewayError extends RequestError {
|
|
|
332
344
|
}
|
|
333
345
|
|
|
334
346
|
export class ServiceUnavailableError extends RequestError {
|
|
335
|
-
static get
|
|
347
|
+
static get status () { return 503 }
|
|
336
348
|
|
|
337
349
|
constructor (message) {
|
|
338
350
|
super(message)
|
|
@@ -342,7 +354,7 @@ export class ServiceUnavailableError extends RequestError {
|
|
|
342
354
|
}
|
|
343
355
|
|
|
344
356
|
export class GatewayTimeoutError extends RequestError {
|
|
345
|
-
static get
|
|
357
|
+
static get status () { return 504 }
|
|
346
358
|
|
|
347
359
|
constructor () {
|
|
348
360
|
super('')
|
|
@@ -352,7 +364,7 @@ export class GatewayTimeoutError extends RequestError {
|
|
|
352
364
|
}
|
|
353
365
|
|
|
354
366
|
export class HTTPVersionNotSupportedError extends RequestError {
|
|
355
|
-
static get
|
|
367
|
+
static get status () { return 505 }
|
|
356
368
|
|
|
357
369
|
constructor (message) {
|
|
358
370
|
super(message)
|
|
@@ -362,7 +374,7 @@ export class HTTPVersionNotSupportedError extends RequestError {
|
|
|
362
374
|
}
|
|
363
375
|
|
|
364
376
|
export class VariantAlsoNegotiatesError extends RequestError {
|
|
365
|
-
static get
|
|
377
|
+
static get status () { return 506 }
|
|
366
378
|
|
|
367
379
|
constructor (message) {
|
|
368
380
|
super(message)
|
|
@@ -372,7 +384,7 @@ export class VariantAlsoNegotiatesError extends RequestError {
|
|
|
372
384
|
}
|
|
373
385
|
|
|
374
386
|
export class InsufficientStorageError extends RequestError {
|
|
375
|
-
static get
|
|
387
|
+
static get status () { return 507 }
|
|
376
388
|
|
|
377
389
|
constructor (message) {
|
|
378
390
|
super(message)
|
|
@@ -382,7 +394,7 @@ export class InsufficientStorageError extends RequestError {
|
|
|
382
394
|
}
|
|
383
395
|
|
|
384
396
|
export class LoopDetectedError extends RequestError {
|
|
385
|
-
static get
|
|
397
|
+
static get status () { return 508 }
|
|
386
398
|
|
|
387
399
|
constructor (message) {
|
|
388
400
|
super(message)
|
|
@@ -392,7 +404,7 @@ export class LoopDetectedError extends RequestError {
|
|
|
392
404
|
}
|
|
393
405
|
|
|
394
406
|
export class NotExtendedError extends RequestError {
|
|
395
|
-
static get
|
|
407
|
+
static get status () { return 510 }
|
|
396
408
|
|
|
397
409
|
constructor (message) {
|
|
398
410
|
super(message)
|
|
@@ -402,7 +414,7 @@ export class NotExtendedError extends RequestError {
|
|
|
402
414
|
}
|
|
403
415
|
|
|
404
416
|
export class NetworkAuthenticationRequiredError extends RequestError {
|
|
405
|
-
static get
|
|
417
|
+
static get status () { return 511 }
|
|
406
418
|
|
|
407
419
|
constructor (message) {
|
|
408
420
|
super(message)
|