@arkyn/server 2.0.1-beta.8 → 2.0.1
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.txt +24 -0
- package/README.md +116 -0
- package/dist/api/__test__/deleteRequest.spec.d.ts +2 -0
- package/dist/api/__test__/deleteRequest.spec.d.ts.map +1 -0
- package/dist/api/__test__/deleteRequest.spec.js +84 -0
- package/dist/api/__test__/getRequest.spec.d.ts +2 -0
- package/dist/api/__test__/getRequest.spec.d.ts.map +1 -0
- package/dist/api/__test__/getRequest.spec.js +62 -0
- package/dist/api/__test__/inboxFlowRequest.spec.d.ts +2 -0
- package/dist/api/__test__/inboxFlowRequest.spec.d.ts.map +1 -0
- package/dist/api/__test__/inboxFlowRequest.spec.js +96 -0
- package/dist/api/__test__/makeRequest.spec.d.ts +2 -0
- package/dist/api/__test__/makeRequest.spec.d.ts.map +1 -0
- package/dist/api/__test__/makeRequest.spec.js +80 -0
- package/dist/api/__test__/patchRequest.spec.d.ts +2 -0
- package/dist/api/__test__/patchRequest.spec.d.ts.map +1 -0
- package/dist/api/__test__/patchRequest.spec.js +84 -0
- package/dist/api/__test__/postRequest.spec.d.ts +2 -0
- package/dist/api/__test__/postRequest.spec.d.ts.map +1 -0
- package/dist/api/__test__/postRequest.spec.js +84 -0
- package/dist/api/__test__/putRequest.spec.d.ts +2 -0
- package/dist/api/__test__/putRequest.spec.d.ts.map +1 -0
- package/dist/api/__test__/putRequest.spec.js +84 -0
- package/dist/api/deleteRequest.d.ts +13 -0
- package/dist/api/deleteRequest.d.ts.map +1 -0
- package/dist/api/deleteRequest.js +14 -0
- package/dist/api/getRequest.d.ts +12 -0
- package/dist/api/getRequest.d.ts.map +1 -0
- package/dist/api/getRequest.js +13 -0
- package/dist/api/inboxFlowRequest.d.ts +40 -0
- package/dist/api/inboxFlowRequest.d.ts.map +1 -0
- package/dist/api/inboxFlowRequest.js +63 -0
- package/dist/api/makeRequest.d.ts +38 -0
- package/dist/api/makeRequest.d.ts.map +1 -0
- package/dist/api/makeRequest.js +103 -0
- package/dist/api/patchRequest.d.ts +13 -0
- package/dist/api/patchRequest.d.ts.map +1 -0
- package/dist/api/patchRequest.js +14 -0
- package/dist/api/postRequest.d.ts +13 -0
- package/dist/api/postRequest.d.ts.map +1 -0
- package/dist/api/postRequest.js +14 -0
- package/dist/api/putRequest.d.ts +13 -0
- package/dist/api/putRequest.d.ts.map +1 -0
- package/dist/api/putRequest.js +14 -0
- package/dist/config/__test__/apiInstance.spec.d.ts +2 -0
- package/dist/config/__test__/apiInstance.spec.d.ts.map +1 -0
- package/dist/config/__test__/apiInstance.spec.js +86 -0
- package/dist/config/__test__/inboxFlowInstance.spec.d.ts +2 -0
- package/dist/config/__test__/inboxFlowInstance.spec.d.ts.map +1 -0
- package/dist/config/__test__/inboxFlowInstance.spec.js +48 -0
- package/dist/config/apiInstance.d.ts +80 -0
- package/dist/config/apiInstance.d.ts.map +1 -0
- package/dist/config/apiInstance.js +111 -0
- package/dist/config/inboxFlowInstance.d.ts +44 -0
- package/dist/config/inboxFlowInstance.d.ts.map +1 -0
- package/dist/config/inboxFlowInstance.js +46 -0
- package/dist/http/badResponses/__test__/badGateway.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/badGateway.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/badGateway.spec.js +42 -0
- package/dist/http/badResponses/__test__/badRequest.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/badRequest.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/badRequest.spec.js +40 -0
- package/dist/http/badResponses/__test__/conflict.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/conflict.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/conflict.spec.js +40 -0
- package/dist/http/badResponses/__test__/forbidden.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/forbidden.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/forbidden.spec.js +40 -0
- package/dist/http/badResponses/__test__/notFound.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/notFound.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/notFound.spec.js +40 -0
- package/dist/http/badResponses/__test__/notImplemented.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/notImplemented.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/notImplemented.spec.js +40 -0
- package/dist/http/badResponses/__test__/serverError.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/serverError.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/serverError.spec.js +40 -0
- package/dist/http/badResponses/__test__/unauthorized.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/unauthorized.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/unauthorized.spec.js +40 -0
- package/dist/http/badResponses/__test__/unprocessableEntity.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/unprocessableEntity.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/unprocessableEntity.spec.js +66 -0
- package/dist/http/badResponses/badGateway.d.ts +23 -0
- package/dist/http/badResponses/badGateway.d.ts.map +1 -1
- package/dist/http/badResponses/badGateway.js +24 -1
- package/dist/http/badResponses/badRequest.d.ts +23 -0
- package/dist/http/badResponses/badRequest.d.ts.map +1 -1
- package/dist/http/badResponses/badRequest.js +24 -1
- package/dist/http/badResponses/conflict.d.ts +23 -0
- package/dist/http/badResponses/conflict.d.ts.map +1 -1
- package/dist/http/badResponses/conflict.js +24 -1
- package/dist/http/badResponses/forbidden.d.ts +23 -0
- package/dist/http/badResponses/forbidden.d.ts.map +1 -1
- package/dist/http/badResponses/forbidden.js +25 -2
- package/dist/http/badResponses/notFound.d.ts +23 -0
- package/dist/http/badResponses/notFound.d.ts.map +1 -1
- package/dist/http/badResponses/notFound.js +24 -1
- package/dist/http/badResponses/notImplemented.d.ts +23 -0
- package/dist/http/badResponses/notImplemented.d.ts.map +1 -1
- package/dist/http/badResponses/notImplemented.js +24 -1
- package/dist/http/badResponses/serverError.d.ts +23 -0
- package/dist/http/badResponses/serverError.d.ts.map +1 -1
- package/dist/http/badResponses/serverError.js +24 -1
- package/dist/http/badResponses/unauthorized.d.ts +23 -0
- package/dist/http/badResponses/unauthorized.d.ts.map +1 -1
- package/dist/http/badResponses/unauthorized.js +24 -1
- package/dist/http/badResponses/unprocessableEntity.d.ts +28 -1
- package/dist/http/badResponses/unprocessableEntity.d.ts.map +1 -1
- package/dist/http/badResponses/unprocessableEntity.js +30 -3
- package/dist/http/successResponses/__test__/created.spec.d.ts +2 -0
- package/dist/http/successResponses/__test__/created.spec.d.ts.map +1 -0
- package/dist/http/successResponses/__test__/created.spec.js +57 -0
- package/dist/http/successResponses/__test__/found.spec.d.ts +2 -0
- package/dist/http/successResponses/__test__/found.spec.d.ts.map +1 -0
- package/dist/http/successResponses/__test__/found.spec.js +57 -0
- package/dist/http/successResponses/__test__/noContent.spec.d.ts +2 -0
- package/dist/http/successResponses/__test__/noContent.spec.d.ts.map +1 -0
- package/dist/http/successResponses/__test__/noContent.spec.js +40 -0
- package/dist/http/successResponses/__test__/success.spec.d.ts +2 -0
- package/dist/http/successResponses/__test__/success.spec.d.ts.map +1 -0
- package/dist/http/successResponses/__test__/success.spec.js +60 -0
- package/dist/http/successResponses/__test__/updated.spec.d.ts +2 -0
- package/dist/http/successResponses/__test__/updated.spec.d.ts.map +1 -0
- package/dist/http/successResponses/__test__/updated.spec.js +60 -0
- package/dist/http/successResponses/created.d.ts +25 -0
- package/dist/http/successResponses/created.d.ts.map +1 -1
- package/dist/http/successResponses/created.js +25 -0
- package/dist/http/successResponses/found.d.ts +28 -0
- package/dist/http/successResponses/found.d.ts.map +1 -1
- package/dist/http/successResponses/found.js +28 -0
- package/dist/http/successResponses/noContent.d.ts +16 -1
- package/dist/http/successResponses/noContent.d.ts.map +1 -1
- package/dist/http/successResponses/noContent.js +16 -8
- package/dist/http/successResponses/success.d.ts +25 -0
- package/dist/http/successResponses/success.d.ts.map +1 -1
- package/dist/http/successResponses/success.js +25 -0
- package/dist/http/successResponses/updated.d.ts +25 -0
- package/dist/http/successResponses/updated.d.ts.map +1 -1
- package/dist/http/successResponses/updated.js +25 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -0
- package/dist/services/__test__/decodeRequestBody.spec.d.ts +2 -0
- package/dist/services/__test__/decodeRequestBody.spec.d.ts.map +1 -0
- package/dist/services/__test__/decodeRequestBody.spec.js +39 -0
- package/dist/services/__test__/errorHandler.spec.d.ts +2 -0
- package/dist/services/__test__/errorHandler.spec.d.ts.map +1 -0
- package/dist/services/__test__/errorHandler.spec.js +115 -0
- package/dist/services/__test__/formParse.spec.d.ts +2 -0
- package/dist/services/__test__/formParse.spec.d.ts.map +1 -0
- package/dist/services/__test__/formParse.spec.js +78 -0
- package/dist/services/__test__/getCaller.spec.d.ts +2 -0
- package/dist/services/__test__/getCaller.spec.d.ts.map +1 -0
- package/dist/services/__test__/getCaller.spec.js +60 -0
- package/dist/services/__test__/getScopedParams.spec.d.ts +2 -0
- package/dist/services/__test__/getScopedParams.spec.d.ts.map +1 -0
- package/dist/services/__test__/getScopedParams.spec.js +51 -0
- package/dist/services/__test__/schemaValidator.spec.d.ts +2 -0
- package/dist/services/__test__/schemaValidator.spec.d.ts.map +1 -0
- package/dist/services/__test__/schemaValidator.spec.js +89 -0
- package/dist/services/decodeErrorMessageFromRequest.d.ts +17 -0
- package/dist/services/decodeErrorMessageFromRequest.d.ts.map +1 -0
- package/dist/services/decodeErrorMessageFromRequest.js +30 -0
- package/dist/services/decodeRequestBody.d.ts.map +1 -1
- package/dist/services/decodeRequestBody.js +12 -16
- package/dist/services/errorHandler.d.ts +42 -1
- package/dist/services/errorHandler.d.ts.map +1 -1
- package/dist/services/errorHandler.js +42 -0
- package/dist/services/formParse.d.ts.map +1 -1
- package/dist/services/formParse.js +4 -2
- package/dist/services/getCaller.d.ts +17 -0
- package/dist/services/getCaller.d.ts.map +1 -0
- package/dist/services/getCaller.js +45 -0
- package/dist/services/httpDebug.d.ts +35 -0
- package/dist/services/httpDebug.d.ts.map +1 -0
- package/dist/services/httpDebug.js +56 -0
- package/dist/services/schemaValidator.d.ts +13 -0
- package/dist/services/schemaValidator.d.ts.map +1 -0
- package/dist/services/schemaValidator.js +51 -0
- package/package.json +13 -6
- package/src/api/__test__/deleteRequest.spec.ts +107 -0
- package/src/api/__test__/getRequest.spec.ts +76 -0
- package/src/api/__test__/inboxFlowRequest.spec.ts +125 -0
- package/src/api/__test__/makeRequest.spec.ts +121 -0
- package/src/api/__test__/patchRequest.spec.ts +125 -0
- package/src/api/__test__/postRequest.spec.ts +125 -0
- package/src/api/__test__/putRequest.spec.ts +125 -0
- package/src/api/deleteRequest.ts +22 -0
- package/src/api/getRequest.ts +20 -0
- package/src/api/inboxFlowRequest.ts +76 -0
- package/src/api/makeRequest.ts +117 -0
- package/src/api/patchRequest.ts +22 -0
- package/src/api/postRequest.ts +22 -0
- package/src/api/putRequest.ts +22 -0
- package/src/config/__test__/apiInstance.spec.ts +129 -0
- package/src/config/__test__/inboxFlowInstance.spec.ts +61 -0
- package/src/config/apiInstance.ts +148 -0
- package/src/config/inboxFlowInstance.ts +65 -0
- package/src/http/badResponses/__test__/badGateway.spec.ts +50 -0
- package/src/http/badResponses/__test__/badRequest.spec.ts +50 -0
- package/src/http/badResponses/__test__/conflict.spec.ts +50 -0
- package/src/http/badResponses/__test__/forbidden.spec.ts +50 -0
- package/src/http/badResponses/__test__/notFound.spec.ts +50 -0
- package/src/http/badResponses/__test__/notImplemented.spec.ts +50 -0
- package/src/http/badResponses/__test__/serverError.spec.ts +50 -0
- package/src/http/badResponses/__test__/unauthorized.spec.ts +50 -0
- package/src/http/badResponses/__test__/unprocessableEntity.spec.ts +76 -0
- package/src/http/badResponses/badGateway.ts +29 -2
- package/src/http/badResponses/badRequest.ts +29 -2
- package/src/http/badResponses/conflict.ts +29 -2
- package/src/http/badResponses/forbidden.ts +30 -3
- package/src/http/badResponses/notFound.ts +29 -2
- package/src/http/badResponses/notImplemented.ts +29 -2
- package/src/http/badResponses/serverError.ts +29 -2
- package/src/http/badResponses/unauthorized.ts +29 -2
- package/src/http/badResponses/unprocessableEntity.ts +33 -2
- package/src/http/successResponses/__test__/created.spec.ts +65 -0
- package/src/http/successResponses/__test__/found.spec.ts +65 -0
- package/src/http/successResponses/__test__/noContent.spec.ts +49 -0
- package/src/http/successResponses/__test__/success.spec.ts +68 -0
- package/src/http/successResponses/__test__/updated.spec.ts +68 -0
- package/src/http/successResponses/created.ts +31 -2
- package/src/http/successResponses/found.ts +32 -0
- package/src/http/successResponses/noContent.ts +20 -11
- package/src/http/successResponses/success.ts +31 -2
- package/src/http/successResponses/updated.ts +31 -2
- package/src/index.ts +9 -1
- package/src/services/__test__/decodeRequestBody.spec.ts +51 -0
- package/src/services/__test__/errorHandler.spec.ts +133 -0
- package/src/services/__test__/formParse.spec.ts +96 -0
- package/src/services/__test__/getCaller.spec.ts +78 -0
- package/src/services/__test__/getScopedParams.spec.ts +68 -0
- package/src/services/__test__/schemaValidator.spec.ts +106 -0
- package/src/services/decodeErrorMessageFromRequest.ts +36 -0
- package/src/services/decodeRequestBody.ts +11 -15
- package/src/services/errorHandler.ts +45 -1
- package/src/services/formParse.ts +4 -5
- package/src/services/getCaller.ts +39 -21
- package/src/services/httpDebug.ts +46 -5
- package/vitest.config.ts +5 -0
- package/dist/http/httpDebug.d.ts +0 -3
- package/dist/http/httpDebug.d.ts.map +0 -1
- package/dist/http/httpDebug.js +0 -15
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { NotFound } from "../notFound";
|
|
3
|
+
describe("NotFound", () => {
|
|
4
|
+
it("should create an instance with the correct properties", () => {
|
|
5
|
+
const message = "Resource not found";
|
|
6
|
+
const cause = { reason: "ID does not exist" };
|
|
7
|
+
const error = new NotFound(message, cause);
|
|
8
|
+
expect(error.body).toEqual({ name: "NotFound", message });
|
|
9
|
+
expect(error.status).toBe(404);
|
|
10
|
+
expect(error.statusText).toBe(message);
|
|
11
|
+
expect(error.cause).toBe(JSON.stringify(cause));
|
|
12
|
+
});
|
|
13
|
+
it("should create an instance without a cause", () => {
|
|
14
|
+
const message = "Resource not found";
|
|
15
|
+
const error = new NotFound(message);
|
|
16
|
+
expect(error.body).toEqual({ name: "NotFound", message });
|
|
17
|
+
expect(error.status).toBe(404);
|
|
18
|
+
expect(error.statusText).toBe(message);
|
|
19
|
+
expect(error.cause).toBeUndefined();
|
|
20
|
+
});
|
|
21
|
+
it("should return a Response object from toResponse", async () => {
|
|
22
|
+
const message = "Resource not found";
|
|
23
|
+
const error = new NotFound(message);
|
|
24
|
+
const response = error.toResponse();
|
|
25
|
+
expect(response.status).toBe(404);
|
|
26
|
+
expect(response.statusText).toBe(message);
|
|
27
|
+
expect(response.headers.get("Content-Type")).toBe("application/json");
|
|
28
|
+
const body = await response.json();
|
|
29
|
+
expect(body).toEqual({ name: "NotFound", message });
|
|
30
|
+
});
|
|
31
|
+
it("should return a Response object from toJson", async () => {
|
|
32
|
+
const message = "Resource not found";
|
|
33
|
+
const error = new NotFound(message);
|
|
34
|
+
const response = error.toJson();
|
|
35
|
+
expect(response.status).toBe(404);
|
|
36
|
+
expect(response.statusText).toBe(message);
|
|
37
|
+
const body = await response.json();
|
|
38
|
+
expect(body).toEqual({ name: "NotFound", message });
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notImplemented.spec.d.ts","sourceRoot":"","sources":["../../../../src/http/badResponses/__test__/notImplemented.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { NotImplemented } from "../notImplemented";
|
|
3
|
+
describe("NotImplemented", () => {
|
|
4
|
+
it("should create an instance with the correct properties", () => {
|
|
5
|
+
const message = "Feature not implemented";
|
|
6
|
+
const cause = { reason: "Under development" };
|
|
7
|
+
const error = new NotImplemented(message, cause);
|
|
8
|
+
expect(error.body).toEqual({ name: "NotImplemented", message });
|
|
9
|
+
expect(error.status).toBe(501);
|
|
10
|
+
expect(error.statusText).toBe(message);
|
|
11
|
+
expect(error.cause).toBe(JSON.stringify(cause));
|
|
12
|
+
});
|
|
13
|
+
it("should create an instance without a cause", () => {
|
|
14
|
+
const message = "Feature not implemented";
|
|
15
|
+
const error = new NotImplemented(message);
|
|
16
|
+
expect(error.body).toEqual({ name: "NotImplemented", message });
|
|
17
|
+
expect(error.status).toBe(501);
|
|
18
|
+
expect(error.statusText).toBe(message);
|
|
19
|
+
expect(error.cause).toBeUndefined();
|
|
20
|
+
});
|
|
21
|
+
it("should return a Response object from toResponse", async () => {
|
|
22
|
+
const message = "Feature not implemented";
|
|
23
|
+
const error = new NotImplemented(message);
|
|
24
|
+
const response = error.toResponse();
|
|
25
|
+
expect(response.status).toBe(501);
|
|
26
|
+
expect(response.statusText).toBe(message);
|
|
27
|
+
expect(response.headers.get("Content-Type")).toBe("application/json");
|
|
28
|
+
const body = await response.json();
|
|
29
|
+
expect(body).toEqual({ name: "NotImplemented", message });
|
|
30
|
+
});
|
|
31
|
+
it("should return a Response object from toJson", async () => {
|
|
32
|
+
const message = "Feature not implemented";
|
|
33
|
+
const error = new NotImplemented(message);
|
|
34
|
+
const response = error.toJson();
|
|
35
|
+
expect(response.status).toBe(501);
|
|
36
|
+
expect(response.statusText).toBe(message);
|
|
37
|
+
const body = await response.json();
|
|
38
|
+
expect(body).toEqual({ name: "NotImplemented", message });
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serverError.spec.d.ts","sourceRoot":"","sources":["../../../../src/http/badResponses/__test__/serverError.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { ServerError } from "../serverError";
|
|
3
|
+
describe("ServerError", () => {
|
|
4
|
+
it("should create an instance with the correct properties", () => {
|
|
5
|
+
const message = "Internal server error occurred";
|
|
6
|
+
const cause = { reason: "Database connection failed" };
|
|
7
|
+
const error = new ServerError(message, cause);
|
|
8
|
+
expect(error.body).toEqual({ name: "ServerError", message });
|
|
9
|
+
expect(error.status).toBe(500);
|
|
10
|
+
expect(error.statusText).toBe(message);
|
|
11
|
+
expect(error.cause).toBe(JSON.stringify(cause));
|
|
12
|
+
});
|
|
13
|
+
it("should create an instance without a cause", () => {
|
|
14
|
+
const message = "Internal server error occurred";
|
|
15
|
+
const error = new ServerError(message);
|
|
16
|
+
expect(error.body).toEqual({ name: "ServerError", message });
|
|
17
|
+
expect(error.status).toBe(500);
|
|
18
|
+
expect(error.statusText).toBe(message);
|
|
19
|
+
expect(error.cause).toBeUndefined();
|
|
20
|
+
});
|
|
21
|
+
it("should return a Response object from toResponse", async () => {
|
|
22
|
+
const message = "Internal server error occurred";
|
|
23
|
+
const error = new ServerError(message);
|
|
24
|
+
const response = error.toResponse();
|
|
25
|
+
expect(response.status).toBe(500);
|
|
26
|
+
expect(response.statusText).toBe(message);
|
|
27
|
+
expect(response.headers.get("Content-Type")).toBe("application/json");
|
|
28
|
+
const body = await response.json();
|
|
29
|
+
expect(body).toEqual({ name: "ServerError", message });
|
|
30
|
+
});
|
|
31
|
+
it("should return a Response object from toJson", async () => {
|
|
32
|
+
const message = "Internal server error occurred";
|
|
33
|
+
const error = new ServerError(message);
|
|
34
|
+
const response = error.toJson();
|
|
35
|
+
expect(response.status).toBe(500);
|
|
36
|
+
expect(response.statusText).toBe(message);
|
|
37
|
+
const body = await response.json();
|
|
38
|
+
expect(body).toEqual({ name: "ServerError", message });
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unauthorized.spec.d.ts","sourceRoot":"","sources":["../../../../src/http/badResponses/__test__/unauthorized.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { Unauthorized } from "../unauthorized";
|
|
3
|
+
describe("Unauthorized", () => {
|
|
4
|
+
it("should create an instance with the correct properties", () => {
|
|
5
|
+
const message = "Unauthorized access";
|
|
6
|
+
const cause = { reason: "Invalid token" };
|
|
7
|
+
const error = new Unauthorized(message, cause);
|
|
8
|
+
expect(error.body).toEqual({ name: "Unauthorized", message });
|
|
9
|
+
expect(error.status).toBe(401);
|
|
10
|
+
expect(error.statusText).toBe(message);
|
|
11
|
+
expect(error.cause).toBe(JSON.stringify(cause));
|
|
12
|
+
});
|
|
13
|
+
it("should create an instance without a cause", () => {
|
|
14
|
+
const message = "Unauthorized access";
|
|
15
|
+
const error = new Unauthorized(message);
|
|
16
|
+
expect(error.body).toEqual({ name: "Unauthorized", message });
|
|
17
|
+
expect(error.status).toBe(401);
|
|
18
|
+
expect(error.statusText).toBe(message);
|
|
19
|
+
expect(error.cause).toBeUndefined();
|
|
20
|
+
});
|
|
21
|
+
it("should return a Response object from toResponse", async () => {
|
|
22
|
+
const message = "Unauthorized access";
|
|
23
|
+
const error = new Unauthorized(message);
|
|
24
|
+
const response = error.toResponse();
|
|
25
|
+
expect(response.status).toBe(401);
|
|
26
|
+
expect(response.statusText).toBe(message);
|
|
27
|
+
expect(response.headers.get("Content-Type")).toBe("application/json");
|
|
28
|
+
const body = await response.json();
|
|
29
|
+
expect(body).toEqual({ name: "Unauthorized", message });
|
|
30
|
+
});
|
|
31
|
+
it("should return a Response object from toJson", async () => {
|
|
32
|
+
const message = "Unauthorized access";
|
|
33
|
+
const error = new Unauthorized(message);
|
|
34
|
+
const response = error.toJson();
|
|
35
|
+
expect(response.status).toBe(401);
|
|
36
|
+
expect(response.statusText).toBe(message);
|
|
37
|
+
const body = await response.json();
|
|
38
|
+
expect(body).toEqual({ name: "Unauthorized", message });
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unprocessableEntity.spec.d.ts","sourceRoot":"","sources":["../../../../src/http/badResponses/__test__/unprocessableEntity.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { UnprocessableEntity } from "../unprocessableEntity";
|
|
3
|
+
describe("UnprocessableEntity", () => {
|
|
4
|
+
it("should create an instance with the correct properties", () => {
|
|
5
|
+
const props = {
|
|
6
|
+
message: "Validation failed",
|
|
7
|
+
data: { invalidField: "email" },
|
|
8
|
+
fieldErrors: { email: "Invalid format" },
|
|
9
|
+
fields: { email: "example@domain" },
|
|
10
|
+
};
|
|
11
|
+
const error = new UnprocessableEntity(props);
|
|
12
|
+
expect(error.body).toEqual({
|
|
13
|
+
name: "UnprocessableEntity",
|
|
14
|
+
message: props.message,
|
|
15
|
+
data: props.data,
|
|
16
|
+
fieldErrors: props.fieldErrors,
|
|
17
|
+
fields: props.fields,
|
|
18
|
+
});
|
|
19
|
+
expect(error.status).toBe(422);
|
|
20
|
+
expect(error.statusText).toBe(props.message);
|
|
21
|
+
});
|
|
22
|
+
it("should create an instance without optional properties", () => {
|
|
23
|
+
const props = { message: "Validation failed" };
|
|
24
|
+
const error = new UnprocessableEntity(props);
|
|
25
|
+
expect(error.body).toEqual({
|
|
26
|
+
name: "UnprocessableEntity",
|
|
27
|
+
message: props.message,
|
|
28
|
+
data: undefined,
|
|
29
|
+
fieldErrors: undefined,
|
|
30
|
+
fields: undefined,
|
|
31
|
+
});
|
|
32
|
+
expect(error.status).toBe(422);
|
|
33
|
+
expect(error.statusText).toBe(props.message);
|
|
34
|
+
});
|
|
35
|
+
it("should return a Response object from toResponse", async () => {
|
|
36
|
+
const props = { message: "Validation failed" };
|
|
37
|
+
const error = new UnprocessableEntity(props);
|
|
38
|
+
const response = error.toResponse();
|
|
39
|
+
expect(response.status).toBe(422);
|
|
40
|
+
expect(response.statusText).toBe(props.message);
|
|
41
|
+
expect(response.headers.get("Content-Type")).toBe("application/json");
|
|
42
|
+
const body = await response.json();
|
|
43
|
+
expect(body).toEqual({
|
|
44
|
+
name: "UnprocessableEntity",
|
|
45
|
+
message: props.message,
|
|
46
|
+
data: undefined,
|
|
47
|
+
fieldErrors: undefined,
|
|
48
|
+
fields: undefined,
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
it("should return a Response object from toJson", async () => {
|
|
52
|
+
const props = { message: "Validation failed" };
|
|
53
|
+
const error = new UnprocessableEntity(props);
|
|
54
|
+
const response = error.toJson();
|
|
55
|
+
expect(response.status).toBe(422);
|
|
56
|
+
expect(response.statusText).toBe(props.message);
|
|
57
|
+
const body = await response.json();
|
|
58
|
+
expect(body).toEqual({
|
|
59
|
+
name: "UnprocessableEntity",
|
|
60
|
+
message: props.message,
|
|
61
|
+
data: undefined,
|
|
62
|
+
fieldErrors: undefined,
|
|
63
|
+
fields: undefined,
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -1,10 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an HTTP error response with a status code of 502 (Bad Gateway).
|
|
3
|
+
* This class is used to standardize the structure of a "Bad Gateway" error response,
|
|
4
|
+
* including the response body, headers, status, and status text.
|
|
5
|
+
*/
|
|
1
6
|
declare class BadGateway {
|
|
2
7
|
body: any;
|
|
3
8
|
cause?: any;
|
|
4
9
|
status: number;
|
|
5
10
|
statusText: string;
|
|
11
|
+
/**
|
|
12
|
+
* Creates an instance of the `BadGateway` class.
|
|
13
|
+
*
|
|
14
|
+
* @param message - A descriptive message explaining the cause of the error.
|
|
15
|
+
* @param cause - Optional additional information about the cause of the error.
|
|
16
|
+
*/
|
|
6
17
|
constructor(message: string, cause?: any);
|
|
18
|
+
/**
|
|
19
|
+
* Converts the `BadGateway` instance into a `Response` object with a JSON body.
|
|
20
|
+
* This method ensures the response has the appropriate headers, status, and status text.
|
|
21
|
+
*
|
|
22
|
+
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
23
|
+
*/
|
|
7
24
|
toResponse(): Response;
|
|
25
|
+
/**
|
|
26
|
+
* Converts the `BadGateway` instance into a `Response` object using the `Response.json` method.
|
|
27
|
+
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
28
|
+
*
|
|
29
|
+
* @returns A `Response` object with the JSON body and response metadata.
|
|
30
|
+
*/
|
|
8
31
|
toJson(): Response;
|
|
9
32
|
}
|
|
10
33
|
export { BadGateway };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"badGateway.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/badGateway.ts"],"names":[],"mappings":"AAEA,cAAM,UAAU;IACd,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"badGateway.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/badGateway.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,cAAM,UAAU;IACd,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAOxC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -1,15 +1,32 @@
|
|
|
1
|
-
import { httpDebug } from "
|
|
1
|
+
import { httpDebug } from "../../services/httpDebug";
|
|
2
|
+
/**
|
|
3
|
+
* Represents an HTTP error response with a status code of 502 (Bad Gateway).
|
|
4
|
+
* This class is used to standardize the structure of a "Bad Gateway" error response,
|
|
5
|
+
* including the response body, headers, status, and status text.
|
|
6
|
+
*/
|
|
2
7
|
class BadGateway {
|
|
3
8
|
body;
|
|
4
9
|
cause;
|
|
5
10
|
status = 502;
|
|
6
11
|
statusText;
|
|
12
|
+
/**
|
|
13
|
+
* Creates an instance of the `BadGateway` class.
|
|
14
|
+
*
|
|
15
|
+
* @param message - A descriptive message explaining the cause of the error.
|
|
16
|
+
* @param cause - Optional additional information about the cause of the error.
|
|
17
|
+
*/
|
|
7
18
|
constructor(message, cause) {
|
|
8
19
|
this.body = { name: "BadGateway", message: message };
|
|
9
20
|
this.statusText = message;
|
|
10
21
|
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
11
22
|
httpDebug("BadGateway", this.body, this.cause);
|
|
12
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Converts the `BadGateway` instance into a `Response` object with a JSON body.
|
|
26
|
+
* This method ensures the response has the appropriate headers, status, and status text.
|
|
27
|
+
*
|
|
28
|
+
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
29
|
+
*/
|
|
13
30
|
toResponse() {
|
|
14
31
|
const responseInit = {
|
|
15
32
|
headers: { "Content-Type": "application/json" },
|
|
@@ -18,6 +35,12 @@ class BadGateway {
|
|
|
18
35
|
};
|
|
19
36
|
return new Response(JSON.stringify(this.body), responseInit);
|
|
20
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Converts the `BadGateway` instance into a `Response` object using the `Response.json` method.
|
|
40
|
+
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
41
|
+
*
|
|
42
|
+
* @returns A `Response` object with the JSON body and response metadata.
|
|
43
|
+
*/
|
|
21
44
|
toJson() {
|
|
22
45
|
const responseInit = {
|
|
23
46
|
status: this.status,
|
|
@@ -1,10 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an HTTP error response with a status code of 400 (Bad Request).
|
|
3
|
+
* This class is used to standardize the structure of a "Bad Request" error response,
|
|
4
|
+
* including the response body, headers, status, and status text.
|
|
5
|
+
*/
|
|
1
6
|
declare class BadRequest {
|
|
2
7
|
body: any;
|
|
3
8
|
cause?: any;
|
|
4
9
|
status: number;
|
|
5
10
|
statusText: string;
|
|
11
|
+
/**
|
|
12
|
+
* Creates an instance of the `BadRequest` class.
|
|
13
|
+
*
|
|
14
|
+
* @param message - A descriptive message explaining the cause of the error.
|
|
15
|
+
* @param cause - Optional additional information about the cause of the error.
|
|
16
|
+
*/
|
|
6
17
|
constructor(message: string, cause?: any);
|
|
18
|
+
/**
|
|
19
|
+
* Converts the `BadRequest` instance into a `Response` object with a JSON body.
|
|
20
|
+
* This method ensures the response has the appropriate headers, status, and status text.
|
|
21
|
+
*
|
|
22
|
+
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
23
|
+
*/
|
|
7
24
|
toResponse(): Response;
|
|
25
|
+
/**
|
|
26
|
+
* Converts the `BadRequest` instance into a `Response` object using the `Response.json` method.
|
|
27
|
+
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
28
|
+
*
|
|
29
|
+
* @returns A `Response` object with the JSON body and response metadata.
|
|
30
|
+
*/
|
|
8
31
|
toJson(): Response;
|
|
9
32
|
}
|
|
10
33
|
export { BadRequest };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"badRequest.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/badRequest.ts"],"names":[],"mappings":"AAEA,cAAM,UAAU;IACd,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"badRequest.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/badRequest.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,cAAM,UAAU;IACd,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAOxC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -1,15 +1,32 @@
|
|
|
1
|
-
import { httpDebug } from "
|
|
1
|
+
import { httpDebug } from "../../services/httpDebug";
|
|
2
|
+
/**
|
|
3
|
+
* Represents an HTTP error response with a status code of 400 (Bad Request).
|
|
4
|
+
* This class is used to standardize the structure of a "Bad Request" error response,
|
|
5
|
+
* including the response body, headers, status, and status text.
|
|
6
|
+
*/
|
|
2
7
|
class BadRequest {
|
|
3
8
|
body;
|
|
4
9
|
cause;
|
|
5
10
|
status = 400;
|
|
6
11
|
statusText;
|
|
12
|
+
/**
|
|
13
|
+
* Creates an instance of the `BadRequest` class.
|
|
14
|
+
*
|
|
15
|
+
* @param message - A descriptive message explaining the cause of the error.
|
|
16
|
+
* @param cause - Optional additional information about the cause of the error.
|
|
17
|
+
*/
|
|
7
18
|
constructor(message, cause) {
|
|
8
19
|
this.body = { name: "BadRequest", message: message };
|
|
9
20
|
this.statusText = message;
|
|
10
21
|
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
11
22
|
httpDebug("BadRequest", this.body, this.cause);
|
|
12
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Converts the `BadRequest` instance into a `Response` object with a JSON body.
|
|
26
|
+
* This method ensures the response has the appropriate headers, status, and status text.
|
|
27
|
+
*
|
|
28
|
+
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
29
|
+
*/
|
|
13
30
|
toResponse() {
|
|
14
31
|
const responseInit = {
|
|
15
32
|
headers: { "Content-Type": "application/json" },
|
|
@@ -18,6 +35,12 @@ class BadRequest {
|
|
|
18
35
|
};
|
|
19
36
|
return new Response(JSON.stringify(this.body), responseInit);
|
|
20
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Converts the `BadRequest` instance into a `Response` object using the `Response.json` method.
|
|
40
|
+
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
41
|
+
*
|
|
42
|
+
* @returns A `Response` object with the JSON body and response metadata.
|
|
43
|
+
*/
|
|
21
44
|
toJson() {
|
|
22
45
|
const responseInit = {
|
|
23
46
|
status: this.status,
|
|
@@ -1,10 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an HTTP error response with a status code of 409 (Conflict).
|
|
3
|
+
* This class is used to standardize the structure of a "Conflict" error response,
|
|
4
|
+
* including the response body, headers, status, and status text.
|
|
5
|
+
*/
|
|
1
6
|
declare class Conflict {
|
|
2
7
|
body: any;
|
|
3
8
|
cause?: any;
|
|
4
9
|
status: number;
|
|
5
10
|
statusText: string;
|
|
11
|
+
/**
|
|
12
|
+
* Creates an instance of the `Conflict` class.
|
|
13
|
+
*
|
|
14
|
+
* @param message - A descriptive message explaining the cause of the conflict.
|
|
15
|
+
* @param cause - Optional additional information about the cause of the conflict.
|
|
16
|
+
*/
|
|
6
17
|
constructor(message: string, cause?: any);
|
|
18
|
+
/**
|
|
19
|
+
* Converts the `Conflict` instance into a `Response` object with a JSON body.
|
|
20
|
+
* This method ensures the response has the appropriate headers, status, and status text.
|
|
21
|
+
*
|
|
22
|
+
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
23
|
+
*/
|
|
7
24
|
toResponse(): Response;
|
|
25
|
+
/**
|
|
26
|
+
* Converts the `Conflict` instance into a `Response` object using the `Response.json` method.
|
|
27
|
+
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
28
|
+
*
|
|
29
|
+
* @returns A `Response` object with the JSON body and response metadata.
|
|
30
|
+
*/
|
|
8
31
|
toJson(): Response;
|
|
9
32
|
}
|
|
10
33
|
export { Conflict };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conflict.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/conflict.ts"],"names":[],"mappings":"AAEA,cAAM,QAAQ;IACZ,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"conflict.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/conflict.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,cAAM,QAAQ;IACZ,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAOxC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
|
@@ -1,15 +1,32 @@
|
|
|
1
|
-
import { httpDebug } from "
|
|
1
|
+
import { httpDebug } from "../../services/httpDebug";
|
|
2
|
+
/**
|
|
3
|
+
* Represents an HTTP error response with a status code of 409 (Conflict).
|
|
4
|
+
* This class is used to standardize the structure of a "Conflict" error response,
|
|
5
|
+
* including the response body, headers, status, and status text.
|
|
6
|
+
*/
|
|
2
7
|
class Conflict {
|
|
3
8
|
body;
|
|
4
9
|
cause;
|
|
5
10
|
status = 409;
|
|
6
11
|
statusText;
|
|
12
|
+
/**
|
|
13
|
+
* Creates an instance of the `Conflict` class.
|
|
14
|
+
*
|
|
15
|
+
* @param message - A descriptive message explaining the cause of the conflict.
|
|
16
|
+
* @param cause - Optional additional information about the cause of the conflict.
|
|
17
|
+
*/
|
|
7
18
|
constructor(message, cause) {
|
|
8
19
|
this.body = { name: "Conflict", message: message };
|
|
9
20
|
this.statusText = message;
|
|
10
21
|
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
11
22
|
httpDebug("Conflict", this.body, this.cause);
|
|
12
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Converts the `Conflict` instance into a `Response` object with a JSON body.
|
|
26
|
+
* This method ensures the response has the appropriate headers, status, and status text.
|
|
27
|
+
*
|
|
28
|
+
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
29
|
+
*/
|
|
13
30
|
toResponse() {
|
|
14
31
|
const responseInit = {
|
|
15
32
|
headers: { "Content-Type": "application/json" },
|
|
@@ -18,6 +35,12 @@ class Conflict {
|
|
|
18
35
|
};
|
|
19
36
|
return new Response(JSON.stringify(this.body), responseInit);
|
|
20
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Converts the `Conflict` instance into a `Response` object using the `Response.json` method.
|
|
40
|
+
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
41
|
+
*
|
|
42
|
+
* @returns A `Response` object with the JSON body and response metadata.
|
|
43
|
+
*/
|
|
21
44
|
toJson() {
|
|
22
45
|
const responseInit = {
|
|
23
46
|
status: this.status,
|
|
@@ -1,10 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an HTTP error response with a status code of 403 (Forbidden).
|
|
3
|
+
* This class is used to standardize the structure of a "Forbidden" error response,
|
|
4
|
+
* including the response body, headers, status, and status text.
|
|
5
|
+
*/
|
|
1
6
|
declare class Forbidden {
|
|
2
7
|
body: any;
|
|
3
8
|
cause?: any;
|
|
4
9
|
status: number;
|
|
5
10
|
statusText: string;
|
|
11
|
+
/**
|
|
12
|
+
* Creates an instance of the `Forbidden` class.
|
|
13
|
+
*
|
|
14
|
+
* @param message - A descriptive message explaining why access is forbidden.
|
|
15
|
+
* @param cause - Optional additional information about the cause of the error.
|
|
16
|
+
*/
|
|
6
17
|
constructor(message: string, cause?: any);
|
|
18
|
+
/**
|
|
19
|
+
* Converts the `Forbidden` instance into a `Response` object with a JSON body.
|
|
20
|
+
* This method ensures the response has the appropriate headers, status, and status text.
|
|
21
|
+
*
|
|
22
|
+
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
23
|
+
*/
|
|
7
24
|
toResponse(): Response;
|
|
25
|
+
/**
|
|
26
|
+
* Converts the `Forbidden` instance into a `Response` object using the `Response.json` method.
|
|
27
|
+
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
28
|
+
*
|
|
29
|
+
* @returns A `Response` object with the JSON body and response metadata.
|
|
30
|
+
*/
|
|
8
31
|
toJson(): Response;
|
|
9
32
|
}
|
|
10
33
|
export { Forbidden };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"forbidden.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/forbidden.ts"],"names":[],"mappings":"AAEA,cAAM,SAAS;IACb,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"forbidden.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/forbidden.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,cAAM,SAAS;IACb,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAOxC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -1,15 +1,32 @@
|
|
|
1
|
-
import { httpDebug } from "
|
|
1
|
+
import { httpDebug } from "../../services/httpDebug";
|
|
2
|
+
/**
|
|
3
|
+
* Represents an HTTP error response with a status code of 403 (Forbidden).
|
|
4
|
+
* This class is used to standardize the structure of a "Forbidden" error response,
|
|
5
|
+
* including the response body, headers, status, and status text.
|
|
6
|
+
*/
|
|
2
7
|
class Forbidden {
|
|
3
8
|
body;
|
|
4
9
|
cause;
|
|
5
|
-
status =
|
|
10
|
+
status = 403;
|
|
6
11
|
statusText;
|
|
12
|
+
/**
|
|
13
|
+
* Creates an instance of the `Forbidden` class.
|
|
14
|
+
*
|
|
15
|
+
* @param message - A descriptive message explaining why access is forbidden.
|
|
16
|
+
* @param cause - Optional additional information about the cause of the error.
|
|
17
|
+
*/
|
|
7
18
|
constructor(message, cause) {
|
|
8
19
|
this.body = { name: "Forbidden", message: message };
|
|
9
20
|
this.statusText = message;
|
|
10
21
|
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
11
22
|
httpDebug("Forbidden", this.body, this.cause);
|
|
12
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Converts the `Forbidden` instance into a `Response` object with a JSON body.
|
|
26
|
+
* This method ensures the response has the appropriate headers, status, and status text.
|
|
27
|
+
*
|
|
28
|
+
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
29
|
+
*/
|
|
13
30
|
toResponse() {
|
|
14
31
|
const responseInit = {
|
|
15
32
|
headers: { "Content-Type": "application/json" },
|
|
@@ -18,6 +35,12 @@ class Forbidden {
|
|
|
18
35
|
};
|
|
19
36
|
return new Response(JSON.stringify(this.body), responseInit);
|
|
20
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Converts the `Forbidden` instance into a `Response` object using the `Response.json` method.
|
|
40
|
+
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
41
|
+
*
|
|
42
|
+
* @returns A `Response` object with the JSON body and response metadata.
|
|
43
|
+
*/
|
|
21
44
|
toJson() {
|
|
22
45
|
const responseInit = {
|
|
23
46
|
status: this.status,
|
|
@@ -1,10 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an HTTP error response with a status code of 404 (Not Found).
|
|
3
|
+
* This class is used to standardize the structure of a "Not Found" error response,
|
|
4
|
+
* including the response body, headers, status, and status text.
|
|
5
|
+
*/
|
|
1
6
|
declare class NotFound {
|
|
2
7
|
body: any;
|
|
3
8
|
cause?: any;
|
|
4
9
|
status: number;
|
|
5
10
|
statusText: string;
|
|
11
|
+
/**
|
|
12
|
+
* Creates an instance of the `NotFound` class.
|
|
13
|
+
*
|
|
14
|
+
* @param message - A descriptive message explaining the reason the resource was not found.
|
|
15
|
+
* @param cause - Optional additional information about the cause of the error.
|
|
16
|
+
*/
|
|
6
17
|
constructor(message: string, cause?: any);
|
|
18
|
+
/**
|
|
19
|
+
* Converts the `NotFound` instance into a `Response` object with a JSON body.
|
|
20
|
+
* This method ensures the response has the appropriate headers, status, and status text.
|
|
21
|
+
*
|
|
22
|
+
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
23
|
+
*/
|
|
7
24
|
toResponse(): Response;
|
|
25
|
+
/**
|
|
26
|
+
* Converts the `NotFound` instance into a `Response` object using the `Response.json` method.
|
|
27
|
+
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
28
|
+
*
|
|
29
|
+
* @returns A `Response` object with the JSON body and response metadata.
|
|
30
|
+
*/
|
|
8
31
|
toJson(): Response;
|
|
9
32
|
}
|
|
10
33
|
export { NotFound };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notFound.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/notFound.ts"],"names":[],"mappings":"AAEA,cAAM,QAAQ;IACZ,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"notFound.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/notFound.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,cAAM,QAAQ;IACZ,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAOxC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|