spooder 4.0.1 → 4.0.2
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 +14 -0
- package/package.json +1 -1
- package/src/api.d.ts +4 -0
- package/src/api.ts +2 -0
package/README.md
CHANGED
|
@@ -458,6 +458,20 @@ server.route('/test/route', (req, url) => {
|
|
|
458
458
|
server.route('/redirect', () => Response.redirect('/redirected', 301));
|
|
459
459
|
```
|
|
460
460
|
|
|
461
|
+
### Status Code Text
|
|
462
|
+
|
|
463
|
+
`spooder` exposes `HTTP_STATUS_CODE` to convieniently access status code text.
|
|
464
|
+
|
|
465
|
+
```ts
|
|
466
|
+
import { HTTP_STATUS_CODE } from 'spooder';
|
|
467
|
+
|
|
468
|
+
server.default((req, status_code) => {
|
|
469
|
+
// status_code: 404
|
|
470
|
+
// Body: Not Found
|
|
471
|
+
return new Response(HTTP_STATUS_CODE[status_code], { status: status_code });
|
|
472
|
+
});
|
|
473
|
+
```
|
|
474
|
+
|
|
461
475
|
<a id="api-routing-request-handler"></a>
|
|
462
476
|
## API > Routing > RequestHandler
|
|
463
477
|
|
package/package.json
CHANGED
package/src/api.d.ts
CHANGED
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
/// <reference types="node" />
|
|
5
5
|
import fs from 'node:fs/promises';
|
|
6
6
|
import { Blob } from 'node:buffer';
|
|
7
|
+
export declare const HTTP_STATUS_CODE: {
|
|
8
|
+
[errorCode: number]: string | undefined;
|
|
9
|
+
[errorCode: string]: string | undefined;
|
|
10
|
+
};
|
|
7
11
|
export declare class ErrorWithMetadata extends Error {
|
|
8
12
|
metadata: Record<string, unknown>;
|
|
9
13
|
constructor(message: string, metadata: Record<string, unknown>);
|
package/src/api.ts
CHANGED
|
@@ -7,6 +7,8 @@ import { log } from './utils';
|
|
|
7
7
|
import crypto from 'crypto';
|
|
8
8
|
import { Blob } from 'node:buffer';
|
|
9
9
|
|
|
10
|
+
export const HTTP_STATUS_CODE = http.STATUS_CODES;
|
|
11
|
+
|
|
10
12
|
export class ErrorWithMetadata extends Error {
|
|
11
13
|
constructor(message: string, public metadata: Record<string, unknown>) {
|
|
12
14
|
super(message);
|