@cfworker/web 5.0.2 → 5.0.4

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.
@@ -1,7 +1,7 @@
1
1
  export declare class HttpError extends Error {
2
2
  readonly status: number;
3
3
  readonly statusText: string;
4
- readonly body: string | object;
5
- constructor(status: number, body: string | object);
4
+ readonly body: string | object | null;
5
+ constructor(status: number, body?: string | object | null);
6
6
  toResponse(): Response;
7
7
  }
@@ -9,7 +9,7 @@ class HttpError extends Error {
9
9
  status;
10
10
  statusText;
11
11
  body;
12
- constructor(status, body) {
12
+ constructor(status, body = null) {
13
13
  const statusText = statuses_1.default.message[status];
14
14
  super(statusText);
15
15
  this.name = this.constructor.name;
@@ -18,20 +18,21 @@ class HttpError extends Error {
18
18
  }
19
19
  this.status = status;
20
20
  this.statusText = statusText;
21
- this.body = body;
21
+ this.body = statuses_1.default.empty[this.status] ? null : (body ?? statusText);
22
22
  }
23
23
  toResponse() {
24
- let body = this.body || this.statusText;
25
- let contentType;
26
- if (typeof body === 'string') {
27
- contentType = 'text/plain';
24
+ let body = this.body;
25
+ const headers = {};
26
+ if (body === null) {
27
+ }
28
+ else if (typeof body === 'string') {
29
+ headers['content-type'] = 'text/plain';
28
30
  }
29
31
  else {
30
- contentType = 'application/json';
32
+ headers['content-type'] = 'application/json';
31
33
  body = JSON.stringify(body);
32
34
  }
33
35
  const { status, statusText } = this;
34
- const headers = { 'content-type': contentType };
35
36
  return new Response(body, { status, statusText, headers });
36
37
  }
37
38
  }
@@ -1,7 +1,7 @@
1
1
  export declare class HttpError extends Error {
2
2
  readonly status: number;
3
3
  readonly statusText: string;
4
- readonly body: string | object;
5
- constructor(status: number, body: string | object);
4
+ readonly body: string | object | null;
5
+ constructor(status: number, body?: string | object | null);
6
6
  toResponse(): Response;
7
7
  }
@@ -3,7 +3,7 @@ export class HttpError extends Error {
3
3
  status;
4
4
  statusText;
5
5
  body;
6
- constructor(status, body) {
6
+ constructor(status, body = null) {
7
7
  const statusText = statuses.message[status];
8
8
  super(statusText);
9
9
  this.name = this.constructor.name;
@@ -12,20 +12,21 @@ export class HttpError extends Error {
12
12
  }
13
13
  this.status = status;
14
14
  this.statusText = statusText;
15
- this.body = body;
15
+ this.body = statuses.empty[this.status] ? null : (body ?? statusText);
16
16
  }
17
17
  toResponse() {
18
- let body = this.body || this.statusText;
19
- let contentType;
20
- if (typeof body === 'string') {
21
- contentType = 'text/plain';
18
+ let body = this.body;
19
+ const headers = {};
20
+ if (body === null) {
21
+ }
22
+ else if (typeof body === 'string') {
23
+ headers['content-type'] = 'text/plain';
22
24
  }
23
25
  else {
24
- contentType = 'application/json';
26
+ headers['content-type'] = 'application/json';
25
27
  body = JSON.stringify(body);
26
28
  }
27
29
  const { status, statusText } = this;
28
- const headers = { 'content-type': contentType };
29
30
  return new Response(body, { status, statusText, headers });
30
31
  }
31
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cfworker/web",
3
- "version": "5.0.2",
3
+ "version": "5.0.4",
4
4
  "description": "Web framework for Cloudflare Workers and service workers, inspired by Koa and fastify",
5
5
  "keywords": [
6
6
  "middleware",
@@ -45,7 +45,7 @@
45
45
  "test": "node ../../test.mjs"
46
46
  },
47
47
  "dependencies": {
48
- "@cfworker/json-schema": "^4.0.2",
48
+ "@cfworker/json-schema": "^4.0.3",
49
49
  "@types/html-escaper": "^3.0.2",
50
50
  "@types/statuses": "^2.0.5",
51
51
  "cookie": "^1.0.2",
@@ -63,7 +63,7 @@
63
63
  "jsonpointer": "^5.0.1",
64
64
  "mocha": "^11.0.1",
65
65
  "typescript": "^5.7.2",
66
- "wrangler": "^3.92.0"
66
+ "wrangler": "^3.95.0"
67
67
  },
68
68
  "tshy": {
69
69
  "exports": {