@arkyn/server 3.0.1-beta.21 → 3.0.1-beta.22
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/package.json +1 -1
- package/src/api/arkynLogRequest.ts +0 -118
- package/src/api/deleteRequest.ts +0 -22
- package/src/api/getRequest.ts +0 -20
- package/src/api/makeRequest.ts +0 -118
- package/src/api/patchRequest.ts +0 -22
- package/src/api/postRequest.ts +0 -22
- package/src/api/putRequest.ts +0 -22
- package/src/config/apiInstance.ts +0 -148
- package/src/config/arkynLogInstance.ts +0 -70
- package/src/http/badResponses/badGateway.ts +0 -63
- package/src/http/badResponses/badRequest.ts +0 -63
- package/src/http/badResponses/conflict.ts +0 -63
- package/src/http/badResponses/forbidden.ts +0 -63
- package/src/http/badResponses/notFound.ts +0 -63
- package/src/http/badResponses/notImplemented.ts +0 -63
- package/src/http/badResponses/serverError.ts +0 -63
- package/src/http/badResponses/unauthorized.ts +0 -63
- package/src/http/badResponses/unprocessableEntity.ts +0 -79
- package/src/http/successResponses/created.ts +0 -64
- package/src/http/successResponses/found.ts +0 -67
- package/src/http/successResponses/noContent.ts +0 -42
- package/src/http/successResponses/success.ts +0 -64
- package/src/http/successResponses/updated.ts +0 -64
- package/src/index.ts +0 -31
- package/src/mapper/arkynLogRequestMapper.ts +0 -73
- package/src/services/decodeErrorMessageFromRequest.ts +0 -36
- package/src/services/decodeRequestBody.ts +0 -43
- package/src/services/errorHandler.ts +0 -99
- package/src/services/formParse.ts +0 -86
- package/src/services/getCaller.ts +0 -82
- package/src/services/getScopedParams.ts +0 -43
- package/src/services/httpDebug.ts +0 -61
- package/src/services/measureRouteExecution.ts +0 -31
- package/src/services/schemaValidator.ts +0 -66
- package/src/types/ApiResponseDTO.ts +0 -19
- package/tsconfig.json +0 -21
- package/vitest.config.ts +0 -5
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { httpDebug } from "../../services/httpDebug";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Represents an HTTP error response with a status code of 400 (Bad Request).
|
|
5
|
-
* This class is used to standardize the structure of a "Bad Request" error response,
|
|
6
|
-
* including the response body, headers, status, and status text.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
class BadRequest {
|
|
10
|
-
body: any;
|
|
11
|
-
cause?: any;
|
|
12
|
-
status: number = 400;
|
|
13
|
-
statusText: string;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Creates an instance of the `BadRequest` class.
|
|
17
|
-
*
|
|
18
|
-
* @param message - A descriptive message explaining the cause of the error.
|
|
19
|
-
* @param cause - Optional additional information about the cause of the error.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
constructor(message: string, cause?: any) {
|
|
23
|
-
this.body = { name: "BadRequest", message: message };
|
|
24
|
-
this.statusText = message;
|
|
25
|
-
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
26
|
-
httpDebug("BadRequest", this.body, this.cause);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Converts the `BadRequest` instance into a `Response` object with a JSON body.
|
|
31
|
-
* This method ensures the response has the appropriate headers, status, and status text.
|
|
32
|
-
*
|
|
33
|
-
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
toResponse(): Response {
|
|
37
|
-
const responseInit: ResponseInit = {
|
|
38
|
-
headers: { "Content-Type": "application/json" },
|
|
39
|
-
status: this.status,
|
|
40
|
-
statusText: this.statusText,
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
return new Response(JSON.stringify(this.body), responseInit);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Converts the `BadRequest` instance into a `Response` object using the `Response.json` method.
|
|
48
|
-
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
49
|
-
*
|
|
50
|
-
* @returns A `Response` object with the JSON body and response metadata.
|
|
51
|
-
*/
|
|
52
|
-
|
|
53
|
-
toJson(): Response {
|
|
54
|
-
const responseInit: ResponseInit = {
|
|
55
|
-
status: this.status,
|
|
56
|
-
statusText: this.statusText,
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
return Response.json(this.body, responseInit);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export { BadRequest };
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { httpDebug } from "../../services/httpDebug";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Represents an HTTP error response with a status code of 409 (Conflict).
|
|
5
|
-
* This class is used to standardize the structure of a "Conflict" error response,
|
|
6
|
-
* including the response body, headers, status, and status text.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
class Conflict {
|
|
10
|
-
body: any;
|
|
11
|
-
cause?: any;
|
|
12
|
-
status: number = 409;
|
|
13
|
-
statusText: string;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Creates an instance of the `Conflict` class.
|
|
17
|
-
*
|
|
18
|
-
* @param message - A descriptive message explaining the cause of the conflict.
|
|
19
|
-
* @param cause - Optional additional information about the cause of the conflict.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
constructor(message: string, cause?: any) {
|
|
23
|
-
this.body = { name: "Conflict", message: message };
|
|
24
|
-
this.statusText = message;
|
|
25
|
-
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
26
|
-
httpDebug("Conflict", this.body, this.cause);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Converts the `Conflict` instance into a `Response` object with a JSON body.
|
|
31
|
-
* This method ensures the response has the appropriate headers, status, and status text.
|
|
32
|
-
*
|
|
33
|
-
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
toResponse(): Response {
|
|
37
|
-
const responseInit: ResponseInit = {
|
|
38
|
-
headers: { "Content-Type": "application/json" },
|
|
39
|
-
status: this.status,
|
|
40
|
-
statusText: this.statusText,
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
return new Response(JSON.stringify(this.body), responseInit);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Converts the `Conflict` instance into a `Response` object using the `Response.json` method.
|
|
48
|
-
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
49
|
-
*
|
|
50
|
-
* @returns A `Response` object with the JSON body and response metadata.
|
|
51
|
-
*/
|
|
52
|
-
|
|
53
|
-
toJson(): Response {
|
|
54
|
-
const responseInit: ResponseInit = {
|
|
55
|
-
status: this.status,
|
|
56
|
-
statusText: this.statusText,
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
return Response.json(this.body, responseInit);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export { Conflict };
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { httpDebug } from "../../services/httpDebug";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Represents an HTTP error response with a status code of 403 (Forbidden).
|
|
5
|
-
* This class is used to standardize the structure of a "Forbidden" error response,
|
|
6
|
-
* including the response body, headers, status, and status text.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
class Forbidden {
|
|
10
|
-
body: any;
|
|
11
|
-
cause?: any;
|
|
12
|
-
status: number = 403;
|
|
13
|
-
statusText: string;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Creates an instance of the `Forbidden` class.
|
|
17
|
-
*
|
|
18
|
-
* @param message - A descriptive message explaining why access is forbidden.
|
|
19
|
-
* @param cause - Optional additional information about the cause of the error.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
constructor(message: string, cause?: any) {
|
|
23
|
-
this.body = { name: "Forbidden", message: message };
|
|
24
|
-
this.statusText = message;
|
|
25
|
-
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
26
|
-
httpDebug("Forbidden", this.body, this.cause);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Converts the `Forbidden` instance into a `Response` object with a JSON body.
|
|
31
|
-
* This method ensures the response has the appropriate headers, status, and status text.
|
|
32
|
-
*
|
|
33
|
-
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
toResponse(): Response {
|
|
37
|
-
const responseInit: ResponseInit = {
|
|
38
|
-
headers: { "Content-Type": "application/json" },
|
|
39
|
-
status: this.status,
|
|
40
|
-
statusText: this.statusText,
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
return new Response(JSON.stringify(this.body), responseInit);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Converts the `Forbidden` instance into a `Response` object using the `Response.json` method.
|
|
48
|
-
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
49
|
-
*
|
|
50
|
-
* @returns A `Response` object with the JSON body and response metadata.
|
|
51
|
-
*/
|
|
52
|
-
|
|
53
|
-
toJson(): Response {
|
|
54
|
-
const responseInit: ResponseInit = {
|
|
55
|
-
status: this.status,
|
|
56
|
-
statusText: this.statusText,
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
return Response.json(this.body, responseInit);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export { Forbidden };
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { httpDebug } from "../../services/httpDebug";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Represents an HTTP error response with a status code of 404 (Not Found).
|
|
5
|
-
* This class is used to standardize the structure of a "Not Found" error response,
|
|
6
|
-
* including the response body, headers, status, and status text.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
class NotFound {
|
|
10
|
-
body: any;
|
|
11
|
-
cause?: any;
|
|
12
|
-
status: number = 404;
|
|
13
|
-
statusText: string;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Creates an instance of the `NotFound` class.
|
|
17
|
-
*
|
|
18
|
-
* @param message - A descriptive message explaining the reason the resource was not found.
|
|
19
|
-
* @param cause - Optional additional information about the cause of the error.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
constructor(message: string, cause?: any) {
|
|
23
|
-
this.body = { name: "NotFound", message: message };
|
|
24
|
-
this.statusText = message;
|
|
25
|
-
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
26
|
-
httpDebug("NotFound", this.body, this.cause);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Converts the `NotFound` instance into a `Response` object with a JSON body.
|
|
31
|
-
* This method ensures the response has the appropriate headers, status, and status text.
|
|
32
|
-
*
|
|
33
|
-
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
toResponse(): Response {
|
|
37
|
-
const responseInit: ResponseInit = {
|
|
38
|
-
headers: { "Content-Type": "application/json" },
|
|
39
|
-
status: this.status,
|
|
40
|
-
statusText: this.statusText,
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
return new Response(JSON.stringify(this.body), responseInit);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Converts the `NotFound` instance into a `Response` object using the `Response.json` method.
|
|
48
|
-
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
49
|
-
*
|
|
50
|
-
* @returns A `Response` object with the JSON body and response metadata.
|
|
51
|
-
*/
|
|
52
|
-
|
|
53
|
-
toJson(): Response {
|
|
54
|
-
const responseInit: ResponseInit = {
|
|
55
|
-
status: this.status,
|
|
56
|
-
statusText: this.statusText,
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
return Response.json(this.body, responseInit);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export { NotFound };
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { httpDebug } from "../../services/httpDebug";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Represents an HTTP error response with a status code of 501 (Not Implemented).
|
|
5
|
-
* This class is used to standardize the structure of a "Not Implemented" error response,
|
|
6
|
-
* including the response body, headers, status, and status text.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
class NotImplemented {
|
|
10
|
-
body: any;
|
|
11
|
-
cause?: any;
|
|
12
|
-
status: number = 501;
|
|
13
|
-
statusText: string;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Creates an instance of the `NotImplemented` class.
|
|
17
|
-
*
|
|
18
|
-
* @param message - A descriptive message explaining why the functionality is not implemented.
|
|
19
|
-
* @param cause - Optional additional information about the cause of the error.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
constructor(message: string, cause?: any) {
|
|
23
|
-
this.body = { name: "NotImplemented", message: message };
|
|
24
|
-
this.statusText = message;
|
|
25
|
-
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
26
|
-
httpDebug("NotImplemented", this.body, this.cause);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Converts the `NotImplemented` instance into a `Response` object with a JSON body.
|
|
31
|
-
* This method ensures the response has the appropriate headers, status, and status text.
|
|
32
|
-
*
|
|
33
|
-
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
toResponse(): Response {
|
|
37
|
-
const responseInit: ResponseInit = {
|
|
38
|
-
headers: { "Content-Type": "application/json" },
|
|
39
|
-
status: this.status,
|
|
40
|
-
statusText: this.statusText,
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
return new Response(JSON.stringify(this.body), responseInit);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Converts the `NotImplemented` instance into a `Response` object using the `Response.json` method.
|
|
48
|
-
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
49
|
-
*
|
|
50
|
-
* @returns A `Response` object with the JSON body and response metadata.
|
|
51
|
-
*/
|
|
52
|
-
|
|
53
|
-
toJson(): Response {
|
|
54
|
-
const responseInit: ResponseInit = {
|
|
55
|
-
status: this.status,
|
|
56
|
-
statusText: this.statusText,
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
return Response.json(this.body, responseInit);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export { NotImplemented };
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { httpDebug } from "../../services/httpDebug";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Represents an HTTP error response with a status code of 500 (Internal Server Error).
|
|
5
|
-
* This class is used to standardize the structure of a "Server Error" response,
|
|
6
|
-
* including the response body, headers, status, and status text.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
class ServerError {
|
|
10
|
-
body: any;
|
|
11
|
-
cause?: any;
|
|
12
|
-
status: number = 500;
|
|
13
|
-
statusText: string;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Creates an instance of the `ServerError` class.
|
|
17
|
-
*
|
|
18
|
-
* @param message - A descriptive message explaining the cause of the server error.
|
|
19
|
-
* @param cause - Optional additional information about the cause of the error.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
constructor(message: string, cause?: any) {
|
|
23
|
-
this.body = { name: "ServerError", message: message };
|
|
24
|
-
this.statusText = message;
|
|
25
|
-
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
26
|
-
httpDebug("ServerError", this.body, this.cause);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Converts the `ServerError` instance into a `Response` object with a JSON body.
|
|
31
|
-
* This method ensures the response has the appropriate headers, status, and status text.
|
|
32
|
-
*
|
|
33
|
-
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
toResponse(): Response {
|
|
37
|
-
const responseInit: ResponseInit = {
|
|
38
|
-
headers: { "Content-Type": "application/json" },
|
|
39
|
-
status: this.status,
|
|
40
|
-
statusText: this.statusText,
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
return new Response(JSON.stringify(this.body), responseInit);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Converts the `ServerError` instance into a `Response` object using the `Response.json` method.
|
|
48
|
-
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
49
|
-
*
|
|
50
|
-
* @returns A `Response` object with the JSON body and response metadata.
|
|
51
|
-
*/
|
|
52
|
-
|
|
53
|
-
toJson(): Response {
|
|
54
|
-
const responseInit: ResponseInit = {
|
|
55
|
-
status: this.status,
|
|
56
|
-
statusText: this.statusText,
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
return Response.json(this.body, responseInit);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export { ServerError };
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { httpDebug } from "../../services/httpDebug";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Represents an HTTP error response with a status code of 401 (Unauthorized).
|
|
5
|
-
* This class is used to standardize the structure of an "Unauthorized" error response,
|
|
6
|
-
* including the response body, headers, status, and status text.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
class Unauthorized {
|
|
10
|
-
body: any;
|
|
11
|
-
cause?: any;
|
|
12
|
-
status: number = 401;
|
|
13
|
-
statusText: string;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Creates an instance of the `Unauthorized` class.
|
|
17
|
-
*
|
|
18
|
-
* @param message - A descriptive message explaining why the request is unauthorized.
|
|
19
|
-
* @param cause - Optional additional information about the cause of the error.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
constructor(message: string, cause?: any) {
|
|
23
|
-
this.body = { name: "Unauthorized", message: message };
|
|
24
|
-
this.statusText = message;
|
|
25
|
-
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
26
|
-
httpDebug("Unauthorized", this.body, this.cause);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Converts the `Unauthorized` instance into a `Response` object with a JSON body.
|
|
31
|
-
* This method ensures the response has the appropriate headers, status, and status text.
|
|
32
|
-
*
|
|
33
|
-
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
toResponse(): Response {
|
|
37
|
-
const responseInit: ResponseInit = {
|
|
38
|
-
headers: { "Content-Type": "application/json" },
|
|
39
|
-
status: this.status,
|
|
40
|
-
statusText: this.statusText,
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
return new Response(JSON.stringify(this.body), responseInit);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Converts the `Unauthorized` instance into a `Response` object using the `Response.json` method.
|
|
48
|
-
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
49
|
-
*
|
|
50
|
-
* @returns A `Response` object with the JSON body and response metadata.
|
|
51
|
-
*/
|
|
52
|
-
|
|
53
|
-
toJson(): Response {
|
|
54
|
-
const responseInit: ResponseInit = {
|
|
55
|
-
status: this.status,
|
|
56
|
-
statusText: this.statusText,
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
return Response.json(this.body, responseInit);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export { Unauthorized };
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { httpDebug } from "../../services/httpDebug";
|
|
2
|
-
|
|
3
|
-
type UnprocessableEntityProps = {
|
|
4
|
-
data?: any;
|
|
5
|
-
fieldErrors?: Record<string, string>;
|
|
6
|
-
fields?: Record<string, string>;
|
|
7
|
-
message?: string;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Represents an HTTP error response with a status code of 422 (Unprocessable Entity).
|
|
12
|
-
* This class is used to standardize the structure of an "Unprocessable Entity" error response,
|
|
13
|
-
* including the response body, headers, status, and status text.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
class UnprocessableEntity {
|
|
17
|
-
body: any;
|
|
18
|
-
status: number = 422;
|
|
19
|
-
statusText: string;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Creates an instance of the `UnprocessableEntity` class.
|
|
23
|
-
*
|
|
24
|
-
* @param props - An object containing details about the error, such as:
|
|
25
|
-
* - `data`: Additional data related to the error.
|
|
26
|
-
* - `fieldErrors`: A record of field-specific error messages.
|
|
27
|
-
* - `fields`: A record of field values that caused the error.
|
|
28
|
-
* - `message`: A descriptive message explaining the error.
|
|
29
|
-
* @param enableDebug - A boolean indicating whether to enable debug logging for this error.
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
constructor(props: UnprocessableEntityProps, enableDebug = false) {
|
|
33
|
-
this.statusText = props.message || "Unprocessable Entity";
|
|
34
|
-
this.body = {
|
|
35
|
-
name: "UnprocessableEntity",
|
|
36
|
-
message: props.message || null,
|
|
37
|
-
data: props.data,
|
|
38
|
-
fieldErrors: props.fieldErrors,
|
|
39
|
-
fields: props.fields,
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
enableDebug && httpDebug("UnprocessableEntity", this.body);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Converts the `UnprocessableEntity` instance into a `Response` object with a JSON body.
|
|
47
|
-
* This method ensures the response has the appropriate headers, status, and status text.
|
|
48
|
-
*
|
|
49
|
-
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
50
|
-
*/
|
|
51
|
-
|
|
52
|
-
toResponse(): Response {
|
|
53
|
-
const responseInit: ResponseInit = {
|
|
54
|
-
headers: { "Content-Type": "application/json" },
|
|
55
|
-
status: this.status,
|
|
56
|
-
statusText: this.statusText,
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
return new Response(JSON.stringify(this.body), responseInit);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Converts the `UnprocessableEntity` instance into a `Response` object using the `Response.json` method.
|
|
64
|
-
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
65
|
-
*
|
|
66
|
-
* @returns A `Response` object with the JSON body and response metadata.
|
|
67
|
-
*/
|
|
68
|
-
|
|
69
|
-
toJson(): Response {
|
|
70
|
-
const responseInit: ResponseInit = {
|
|
71
|
-
status: this.status,
|
|
72
|
-
statusText: this.statusText,
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
return Response.json(this.body, responseInit);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export { UnprocessableEntity };
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents a successful HTTP response with a status code of 201 (Created).
|
|
3
|
-
* This class is used to standardize the structure of a "Created" response,
|
|
4
|
-
* including the response body, headers, status, and status text.
|
|
5
|
-
*
|
|
6
|
-
* @template T - The type of the response body.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
class Created<T> {
|
|
10
|
-
body: T;
|
|
11
|
-
headers: ResponseInit["headers"];
|
|
12
|
-
status: number;
|
|
13
|
-
statusText: string;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Creates an instance of the `Created` class.
|
|
17
|
-
*
|
|
18
|
-
* @param body - The response body to be included in the HTTP response.
|
|
19
|
-
* @param init - Optional initialization object for customizing headers, status, and status text.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
constructor(body: T, init?: ResponseInit) {
|
|
23
|
-
this.body = body;
|
|
24
|
-
this.headers = init?.headers || {};
|
|
25
|
-
this.status = init?.status || 201;
|
|
26
|
-
this.statusText = init?.statusText || "Resource created successfully";
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Converts the `Created` instance into a `Response` object with a JSON body.
|
|
31
|
-
* This method ensures the response has the appropriate headers, status, and status text.
|
|
32
|
-
*
|
|
33
|
-
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
toResponse(): Response {
|
|
37
|
-
const responseInit: ResponseInit = {
|
|
38
|
-
headers: { "Content-Type": "application/json", ...this.headers },
|
|
39
|
-
status: this.status,
|
|
40
|
-
statusText: this.statusText,
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
return new Response(JSON.stringify(this.body), responseInit);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Converts the `Created` instance into a `Response` object using the `Response.json` method.
|
|
48
|
-
* This method is an alternative to `toResponse` for generating JSON responses.
|
|
49
|
-
*
|
|
50
|
-
* @returns A `Response` object with the JSON body and response metadata.
|
|
51
|
-
*/
|
|
52
|
-
|
|
53
|
-
toJson(): Response {
|
|
54
|
-
const responseInit: ResponseInit = {
|
|
55
|
-
headers: this.headers,
|
|
56
|
-
status: this.status,
|
|
57
|
-
statusText: this.statusText,
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
return Response.json(this.body, responseInit);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export { Created };
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents an HTTP 302 Found response.
|
|
3
|
-
* This class is used to create a standardized HTTP response with a status of 302 (Found),
|
|
4
|
-
* including optional headers and a response body.
|
|
5
|
-
*
|
|
6
|
-
* @template T - The type of the response body.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
class Found<T> {
|
|
10
|
-
body: T;
|
|
11
|
-
headers: ResponseInit["headers"];
|
|
12
|
-
status: number;
|
|
13
|
-
statusText: string;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Creates an instance of the `Found` class.
|
|
17
|
-
*
|
|
18
|
-
* @param body - The body of the response.
|
|
19
|
-
* @param init - Optional initialization object to set headers, status, and statusText.
|
|
20
|
-
* - `headers`: Additional headers to include in the response.
|
|
21
|
-
* - `status`: HTTP status code (default is 302).
|
|
22
|
-
* - `statusText`: HTTP status text (default is "Found").
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
constructor(body: T, init?: ResponseInit) {
|
|
26
|
-
this.body = body;
|
|
27
|
-
this.headers = init?.headers || {};
|
|
28
|
-
this.status = init?.status || 302;
|
|
29
|
-
this.statusText = init?.statusText || "Found";
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Converts the `Found` instance into a `Response` object.
|
|
34
|
-
* This method serializes the response body as JSON and includes the appropriate headers.
|
|
35
|
-
*
|
|
36
|
-
* @returns A `Response` object with the serialized JSON body and the specified headers, status, and statusText.
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
toResponse() {
|
|
40
|
-
const responseInit: ResponseInit = {
|
|
41
|
-
headers: { "Content-Type": "application/json", ...this.headers },
|
|
42
|
-
status: this.status,
|
|
43
|
-
statusText: this.statusText,
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
return new Response(JSON.stringify(this.body), responseInit);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Converts the `Found` instance into a JSON response using `Response.json`.
|
|
51
|
-
* This method is an alternative to `toResponse` for creating JSON responses.
|
|
52
|
-
*
|
|
53
|
-
* @returns A `Response` object with the JSON body and the specified headers, status, and statusText.
|
|
54
|
-
*/
|
|
55
|
-
|
|
56
|
-
toJson() {
|
|
57
|
-
const responseInit: ResponseInit = {
|
|
58
|
-
headers: this.headers,
|
|
59
|
-
status: this.status,
|
|
60
|
-
statusText: this.statusText,
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
return Response.json(this.body, responseInit);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export { Found };
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents a successful HTTP response with a status code of 204 (No Content).
|
|
3
|
-
* This class is used to standardize the structure of a "No Content" response,
|
|
4
|
-
* including headers, status, and status text.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
class NoContent {
|
|
8
|
-
headers: ResponseInit["headers"];
|
|
9
|
-
status: number;
|
|
10
|
-
statusText: string;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Creates an instance of the `NoContent` class.
|
|
14
|
-
*
|
|
15
|
-
* @param init - Optional initialization object for customizing headers, status, and status text.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
constructor(init?: ResponseInit) {
|
|
19
|
-
this.headers = init?.headers || {};
|
|
20
|
-
this.status = init?.status || 204;
|
|
21
|
-
this.statusText = init?.statusText ?? "No content";
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Converts the `NoContent` instance into a `Response` object.
|
|
26
|
-
* This method ensures the response has the appropriate headers, status, and status text.
|
|
27
|
-
*
|
|
28
|
-
* @returns A `Response` object with no body and response metadata.
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
toResponse(): Response {
|
|
32
|
-
const responseInit: ResponseInit = {
|
|
33
|
-
headers: this.headers,
|
|
34
|
-
status: this.status,
|
|
35
|
-
statusText: this.statusText,
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
return new Response(null, responseInit);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export { NoContent };
|