@hastehaul/common 2.0.33 → 2.0.34
Sign up to get free protection for your applications and to get access to all the features.
- package/build/errors/bad-request-error.d.ts +3 -1
- package/build/errors/bad-request-error.js +3 -2
- package/build/errors/custom-error.d.ts +2 -1
- package/build/errors/database-error.d.ts +3 -1
- package/build/errors/database-error.js +3 -2
- package/build/errors/not-authorized-error.d.ts +1 -0
- package/build/errors/not-authorized-error.js +1 -1
- package/build/errors/not-found-error.d.ts +4 -2
- package/build/errors/not-found-error.js +4 -3
- package/build/errors/resource-not-found.d.ts +1 -0
- package/build/errors/resource-not-found.js +1 -1
- package/build/errors/system-error.d.ts +4 -2
- package/build/errors/system-error.js +4 -3
- package/build/errors/too-many-request-error.d.ts +1 -0
- package/build/errors/too-many-request-error.js +1 -1
- package/build/middlewares/current-user.js +1 -1
- package/build/middlewares/is-allowed.js +1 -1
- package/package.json +1 -1
@@ -8,6 +8,7 @@ import { CustomError } from "./custom-error";
|
|
8
8
|
*/
|
9
9
|
export declare class BadRequestError extends CustomError {
|
10
10
|
message: string;
|
11
|
+
private code;
|
11
12
|
/**
|
12
13
|
* The HTTP status code associated with the "Bad Request" error (400).
|
13
14
|
*/
|
@@ -17,7 +18,7 @@ export declare class BadRequestError extends CustomError {
|
|
17
18
|
*
|
18
19
|
* @param {string} message - The error message providing details about the "Bad Request" error.
|
19
20
|
*/
|
20
|
-
constructor(message: string);
|
21
|
+
constructor(message: string, code?: string);
|
21
22
|
/**
|
22
23
|
* Method to serialize the "Bad Request" error details into an array of error objects.
|
23
24
|
*
|
@@ -28,5 +29,6 @@ export declare class BadRequestError extends CustomError {
|
|
28
29
|
*/
|
29
30
|
serializeErrors(): Array<{
|
30
31
|
message: string;
|
32
|
+
code: string;
|
31
33
|
}>;
|
32
34
|
}
|
@@ -15,9 +15,10 @@ class BadRequestError extends custom_error_1.CustomError {
|
|
15
15
|
*
|
16
16
|
* @param {string} message - The error message providing details about the "Bad Request" error.
|
17
17
|
*/
|
18
|
-
constructor(message) {
|
18
|
+
constructor(message, code = "2301") {
|
19
19
|
super(message);
|
20
20
|
this.message = message;
|
21
|
+
this.code = code;
|
21
22
|
/**
|
22
23
|
* The HTTP status code associated with the "Bad Request" error (400).
|
23
24
|
*/
|
@@ -33,7 +34,7 @@ class BadRequestError extends custom_error_1.CustomError {
|
|
33
34
|
* @returns {Array<{ message: string }>} - An array containing a single error object with the error message.
|
34
35
|
*/
|
35
36
|
serializeErrors() {
|
36
|
-
return [{ message: this.message }];
|
37
|
+
return [{ message: this.message, code: this.code }];
|
37
38
|
}
|
38
39
|
}
|
39
40
|
exports.BadRequestError = BadRequestError;
|
@@ -23,10 +23,11 @@ export declare abstract class CustomError extends Error {
|
|
23
23
|
* This method returns an array of error objects containing error messages and optional field information.
|
24
24
|
* The specific implementation of this method depends on the type of custom error and how errors are serialized for responses.
|
25
25
|
*
|
26
|
-
* @returns {Array<{ message: string; field?: string }>} - An array of error objects containing error messages and optional field information.
|
26
|
+
* @returns {Array<{ message: string; code: string; field?: string }>} - An array of error objects containing error messages and optional field information.
|
27
27
|
*/
|
28
28
|
abstract serializeErrors(): {
|
29
29
|
message: string;
|
30
|
+
code: string;
|
30
31
|
field?: string;
|
31
32
|
}[];
|
32
33
|
}
|
@@ -7,6 +7,7 @@ import { CustomError } from './custom-error';
|
|
7
7
|
* Instances of this class are thrown when there are errors related to connecting to or interacting with the database.
|
8
8
|
*/
|
9
9
|
export declare class DatabaseError extends CustomError {
|
10
|
+
private code;
|
10
11
|
/**
|
11
12
|
* The HTTP status code associated with the database-related error (500 - Internal Server Error).
|
12
13
|
*/
|
@@ -16,7 +17,7 @@ export declare class DatabaseError extends CustomError {
|
|
16
17
|
*
|
17
18
|
* @param {string} message - The error message providing details about the database-related error.
|
18
19
|
*/
|
19
|
-
constructor(message?: string);
|
20
|
+
constructor(message?: string, code?: string);
|
20
21
|
/**
|
21
22
|
* Method to serialize the database-related error details into an array of error objects.
|
22
23
|
*
|
@@ -27,5 +28,6 @@ export declare class DatabaseError extends CustomError {
|
|
27
28
|
*/
|
28
29
|
serializeErrors: () => Array<{
|
29
30
|
message: string;
|
31
|
+
code: string;
|
30
32
|
}>;
|
31
33
|
}
|
@@ -15,8 +15,9 @@ class DatabaseError extends custom_error_1.CustomError {
|
|
15
15
|
*
|
16
16
|
* @param {string} message - The error message providing details about the database-related error.
|
17
17
|
*/
|
18
|
-
constructor(message = "Error connecting to database") {
|
18
|
+
constructor(message = "Error connecting to database", code = "2303") {
|
19
19
|
super(message);
|
20
|
+
this.code = code;
|
20
21
|
/**
|
21
22
|
* The HTTP status code associated with the database-related error (500 - Internal Server Error).
|
22
23
|
*/
|
@@ -29,7 +30,7 @@ class DatabaseError extends custom_error_1.CustomError {
|
|
29
30
|
*
|
30
31
|
* @returns {Array<{ message: string }>} - An array containing a single error object with the error message.
|
31
32
|
*/
|
32
|
-
this.serializeErrors = () => [{ message: this.message }];
|
33
|
+
this.serializeErrors = () => [{ message: this.message, code: this.code }];
|
33
34
|
Object.setPrototypeOf(this, DatabaseError.prototype);
|
34
35
|
}
|
35
36
|
}
|
@@ -32,7 +32,7 @@ class NotAuthorizedError extends custom_error_1.CustomError {
|
|
32
32
|
* @returns An array containing an object with the error message for the "Not Authorized" error.
|
33
33
|
*/
|
34
34
|
serializeErrors() {
|
35
|
-
return [{ message: 'Not authorized' }];
|
35
|
+
return [{ message: 'Not authorized', code: "2304" }];
|
36
36
|
}
|
37
37
|
}
|
38
38
|
exports.NotAuthorizedError = NotAuthorizedError;
|
@@ -7,6 +7,7 @@ import { CustomError } from "./custom-error";
|
|
7
7
|
* Instances of this class are thrown when a requested resource is not found.
|
8
8
|
*/
|
9
9
|
export declare class NotFoundError extends CustomError {
|
10
|
+
private code;
|
10
11
|
/**
|
11
12
|
* The HTTP status code associated with the "Not Found" error (404).
|
12
13
|
*/
|
@@ -16,16 +17,17 @@ export declare class NotFoundError extends CustomError {
|
|
16
17
|
*
|
17
18
|
* @param {string} message - The error message providing details about the "Not Found" error.
|
18
19
|
*/
|
19
|
-
constructor(message: string);
|
20
|
+
constructor(message: string, code?: string);
|
20
21
|
/**
|
21
22
|
* Method to serialize the "Not Found" error details into an array of error objects.
|
22
23
|
*
|
23
24
|
* This method returns an array containing a single error object with the error message provided during construction.
|
24
25
|
* The array format is consistent with the `CustomError` class's expectation for error serialization.
|
25
26
|
*
|
26
|
-
* @returns {Array<{ message: string }>} - An array containing a single error object with the error message.
|
27
|
+
* @returns {Array<{ message: string; code: string }>} - An array containing a single error object with the error message.
|
27
28
|
*/
|
28
29
|
serializeErrors: () => Array<{
|
29
30
|
message: string;
|
31
|
+
code: string;
|
30
32
|
}>;
|
31
33
|
}
|
@@ -15,8 +15,9 @@ class NotFoundError extends custom_error_1.CustomError {
|
|
15
15
|
*
|
16
16
|
* @param {string} message - The error message providing details about the "Not Found" error.
|
17
17
|
*/
|
18
|
-
constructor(message) {
|
18
|
+
constructor(message, code = "2305") {
|
19
19
|
super(message);
|
20
|
+
this.code = code;
|
20
21
|
/**
|
21
22
|
* The HTTP status code associated with the "Not Found" error (404).
|
22
23
|
*/
|
@@ -27,9 +28,9 @@ class NotFoundError extends custom_error_1.CustomError {
|
|
27
28
|
* This method returns an array containing a single error object with the error message provided during construction.
|
28
29
|
* The array format is consistent with the `CustomError` class's expectation for error serialization.
|
29
30
|
*
|
30
|
-
* @returns {Array<{ message: string }>} - An array containing a single error object with the error message.
|
31
|
+
* @returns {Array<{ message: string; code: string }>} - An array containing a single error object with the error message.
|
31
32
|
*/
|
32
|
-
this.serializeErrors = () => [{ message: this.message }];
|
33
|
+
this.serializeErrors = () => [{ message: this.message, code: this.code }];
|
33
34
|
Object.setPrototypeOf(this, NotFoundError.prototype);
|
34
35
|
}
|
35
36
|
}
|
@@ -31,7 +31,7 @@ class ResourceNotFound extends custom_error_1.CustomError {
|
|
31
31
|
* @returns An array containing an object with the error message for the "Resource Not Found" error.
|
32
32
|
*/
|
33
33
|
serializeErrors() {
|
34
|
-
return [{ message: 'Resource Not Found' }];
|
34
|
+
return [{ message: 'Resource Not Found', code: "2306" }];
|
35
35
|
}
|
36
36
|
}
|
37
37
|
exports.ResourceNotFound = ResourceNotFound;
|
@@ -7,6 +7,7 @@ import { CustomError } from "./custom-error";
|
|
7
7
|
* Instances of this class are thrown when there are unexpected issues in the system.
|
8
8
|
*/
|
9
9
|
export declare class SystemError extends CustomError {
|
10
|
+
private code;
|
10
11
|
/**
|
11
12
|
* The HTTP status code associated with the "System Error" (500 - Internal Server Error).
|
12
13
|
*/
|
@@ -17,16 +18,17 @@ export declare class SystemError extends CustomError {
|
|
17
18
|
* @param {string} message - The error message providing details about the "System Error".
|
18
19
|
* If no message is provided, the default message "Something went wrong" is used.
|
19
20
|
*/
|
20
|
-
constructor(message?: string);
|
21
|
+
constructor(message?: string, code?: string);
|
21
22
|
/**
|
22
23
|
* Method to serialize the "System Error" details into an array of error objects.
|
23
24
|
*
|
24
25
|
* This method returns an array containing a single error object with the error message provided during construction.
|
25
26
|
* The array format is consistent with the `CustomError` class's expectation for error serialization.
|
26
27
|
*
|
27
|
-
* @returns {Array<{ message: string }>} - An array containing a single error object with the error message.
|
28
|
+
* @returns {Array<{ message: string; code: string }>} - An array containing a single error object with the error message.
|
28
29
|
*/
|
29
30
|
serializeErrors: () => Array<{
|
30
31
|
message: string;
|
32
|
+
code: string;
|
31
33
|
}>;
|
32
34
|
}
|
@@ -16,8 +16,9 @@ class SystemError extends custom_error_1.CustomError {
|
|
16
16
|
* @param {string} message - The error message providing details about the "System Error".
|
17
17
|
* If no message is provided, the default message "Something went wrong" is used.
|
18
18
|
*/
|
19
|
-
constructor(message = "Something went wrong") {
|
19
|
+
constructor(message = "Something went wrong", code = "2307") {
|
20
20
|
super(message);
|
21
|
+
this.code = code;
|
21
22
|
/**
|
22
23
|
* The HTTP status code associated with the "System Error" (500 - Internal Server Error).
|
23
24
|
*/
|
@@ -28,9 +29,9 @@ class SystemError extends custom_error_1.CustomError {
|
|
28
29
|
* This method returns an array containing a single error object with the error message provided during construction.
|
29
30
|
* The array format is consistent with the `CustomError` class's expectation for error serialization.
|
30
31
|
*
|
31
|
-
* @returns {Array<{ message: string }>} - An array containing a single error object with the error message.
|
32
|
+
* @returns {Array<{ message: string; code: string }>} - An array containing a single error object with the error message.
|
32
33
|
*/
|
33
|
-
this.serializeErrors = () => [{ message: this.message }];
|
34
|
+
this.serializeErrors = () => [{ message: this.message, code: this.code }];
|
34
35
|
Object.setPrototypeOf(this, SystemError.prototype);
|
35
36
|
}
|
36
37
|
}
|
@@ -45,7 +45,7 @@ const jsonwebtoken_1 = __importStar(require("jsonwebtoken"));
|
|
45
45
|
*/
|
46
46
|
const currentUser = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
47
47
|
req.currentUser = null;
|
48
|
-
const bearerToken = req.headers
|
48
|
+
const bearerToken = req.headers['authorization'];
|
49
49
|
if (!bearerToken) {
|
50
50
|
return next();
|
51
51
|
}
|
@@ -53,7 +53,7 @@ const isAllowed = (req, res, next, hasVersion = false) => {
|
|
53
53
|
// Determine the action based on the HTTP method
|
54
54
|
const action = methodToAction[req.method.toUpperCase()];
|
55
55
|
if (!action) {
|
56
|
-
throw new bad_request_error_1.BadRequestError("Session expired. Please relogin.");
|
56
|
+
throw new bad_request_error_1.BadRequestError("Session expired. Please relogin.", "2201");
|
57
57
|
}
|
58
58
|
if (!resource) {
|
59
59
|
throw new resource_not_found_1.ResourceNotFound();
|