@sn1006/common 1.0.9 → 1.0.12
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/build/errors/bad-request-error.d.ts +3 -3
- package/build/errors/bad-request-error.js +3 -6
- package/build/errors/db-error.d.ts +3 -3
- package/build/errors/db-error.js +3 -6
- package/build/errors/normalized-error.d.ts +9 -0
- package/build/errors/normalized-error.js +11 -0
- package/build/errors/not-authorized-error.d.ts +3 -3
- package/build/errors/not-authorized-error.js +3 -6
- package/build/errors/not-found-error.d.ts +3 -3
- package/build/errors/not-found-error.js +3 -6
- package/build/errors/validation-error.d.ts +3 -3
- package/build/errors/validation-error.js +4 -7
- package/build/index.d.ts +1 -1
- package/build/index.js +1 -1
- package/build/middlewares/error-handler.js +3 -6
- package/package.json +1 -1
- package/build/errors/custom-error.d.ts +0 -9
- package/build/errors/custom-error.js +0 -9
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare class BadRequestError extends
|
|
1
|
+
import { NormalizedError } from './normalized-error';
|
|
2
|
+
export declare class BadRequestError extends NormalizedError {
|
|
3
3
|
message: string;
|
|
4
4
|
status: number;
|
|
5
5
|
constructor(message: string);
|
|
6
|
-
|
|
6
|
+
serializeErrors(): {
|
|
7
7
|
message: string;
|
|
8
8
|
}[];
|
|
9
9
|
}
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.BadRequestError = void 0;
|
|
7
|
-
const
|
|
8
|
-
class BadRequestError extends
|
|
4
|
+
const normalized_error_1 = require("./normalized-error");
|
|
5
|
+
class BadRequestError extends normalized_error_1.NormalizedError {
|
|
9
6
|
constructor(message) {
|
|
10
7
|
super(message);
|
|
11
8
|
this.message = message;
|
|
12
9
|
this.status = 400;
|
|
13
10
|
Object.setPrototypeOf(this, BadRequestError.prototype);
|
|
14
11
|
}
|
|
15
|
-
|
|
12
|
+
serializeErrors() {
|
|
16
13
|
return [{ message: this.message }];
|
|
17
14
|
}
|
|
18
15
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
export default class DBError extends
|
|
1
|
+
import { NormalizedError } from './normalized-error';
|
|
2
|
+
export default class DBError extends NormalizedError {
|
|
3
3
|
status: number;
|
|
4
4
|
constructor();
|
|
5
|
-
|
|
5
|
+
serializeErrors(): {
|
|
6
6
|
message: string;
|
|
7
7
|
field?: string | undefined;
|
|
8
8
|
}[];
|
package/build/errors/db-error.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
7
|
-
class DBError extends
|
|
3
|
+
const normalized_error_1 = require("./normalized-error");
|
|
4
|
+
class DBError extends normalized_error_1.NormalizedError {
|
|
8
5
|
constructor() {
|
|
9
6
|
super('Error connecting to DB');
|
|
10
7
|
this.status = 500;
|
|
11
8
|
Object.setPrototypeOf(this, DBError.prototype);
|
|
12
9
|
}
|
|
13
|
-
|
|
10
|
+
serializeErrors() {
|
|
14
11
|
return [{ message: this.message }];
|
|
15
12
|
}
|
|
16
13
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NormalizedError = void 0;
|
|
4
|
+
// the purpose of this class is to "normalize" errors between services
|
|
5
|
+
class NormalizedError extends Error {
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(message);
|
|
8
|
+
Object.setPrototypeOf(this, NormalizedError.prototype);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.NormalizedError = NormalizedError;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare class NotAuthorizedError extends
|
|
1
|
+
import { NormalizedError } from './normalized-error';
|
|
2
|
+
export declare class NotAuthorizedError extends NormalizedError {
|
|
3
3
|
status: number;
|
|
4
4
|
constructor();
|
|
5
|
-
|
|
5
|
+
serializeErrors(): {
|
|
6
6
|
message: string;
|
|
7
7
|
}[];
|
|
8
8
|
}
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.NotAuthorizedError = void 0;
|
|
7
|
-
const
|
|
8
|
-
class NotAuthorizedError extends
|
|
4
|
+
const normalized_error_1 = require("./normalized-error");
|
|
5
|
+
class NotAuthorizedError extends normalized_error_1.NormalizedError {
|
|
9
6
|
constructor() {
|
|
10
7
|
super('Not authorized');
|
|
11
8
|
this.status = 401;
|
|
12
9
|
Object.setPrototypeOf(this, NotAuthorizedError.prototype);
|
|
13
10
|
}
|
|
14
|
-
|
|
11
|
+
serializeErrors() {
|
|
15
12
|
return [{ message: this.message }];
|
|
16
13
|
}
|
|
17
14
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare class NotFoundError extends
|
|
1
|
+
import { NormalizedError } from './normalized-error';
|
|
2
|
+
export declare class NotFoundError extends NormalizedError {
|
|
3
3
|
status: number;
|
|
4
4
|
constructor();
|
|
5
|
-
|
|
5
|
+
serializeErrors(): {
|
|
6
6
|
message: string;
|
|
7
7
|
}[];
|
|
8
8
|
}
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.NotFoundError = void 0;
|
|
7
|
-
const
|
|
8
|
-
class NotFoundError extends
|
|
4
|
+
const normalized_error_1 = require("./normalized-error");
|
|
5
|
+
class NotFoundError extends normalized_error_1.NormalizedError {
|
|
9
6
|
constructor() {
|
|
10
7
|
super("Resource not found");
|
|
11
8
|
this.status = 404;
|
|
12
9
|
Object.setPrototypeOf(this, NotFoundError.prototype);
|
|
13
10
|
}
|
|
14
|
-
|
|
11
|
+
serializeErrors() {
|
|
15
12
|
return [{ message: this.message }];
|
|
16
13
|
}
|
|
17
14
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { NormalizedError } from './normalized-error';
|
|
2
2
|
import { ValidationError } from 'express-validator';
|
|
3
|
-
declare class CustomValidationError extends
|
|
3
|
+
declare class CustomValidationError extends NormalizedError {
|
|
4
4
|
errors: ValidationError[];
|
|
5
5
|
status: number;
|
|
6
6
|
constructor(errors: ValidationError[]);
|
|
7
|
-
|
|
7
|
+
serializeErrors(): {
|
|
8
8
|
message: any;
|
|
9
9
|
field: string;
|
|
10
10
|
}[];
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
7
|
-
class CustomValidationError extends
|
|
3
|
+
const normalized_error_1 = require("./normalized-error");
|
|
4
|
+
class CustomValidationError extends normalized_error_1.NormalizedError {
|
|
8
5
|
constructor(errors) {
|
|
9
|
-
super("
|
|
6
|
+
super("Validaton error");
|
|
10
7
|
this.errors = errors;
|
|
11
8
|
this.status = 400;
|
|
12
9
|
Object.setPrototypeOf(this, CustomValidationError.prototype);
|
|
13
10
|
}
|
|
14
|
-
|
|
11
|
+
serializeErrors() {
|
|
15
12
|
return this.errors.map(err => {
|
|
16
13
|
const ferr = err;
|
|
17
14
|
return { message: ferr.msg, field: ferr.path };
|
package/build/index.d.ts
CHANGED
package/build/index.js
CHANGED
|
@@ -15,7 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./errors/bad-request-error"), exports);
|
|
18
|
-
__exportStar(require("./errors/
|
|
18
|
+
__exportStar(require("./errors/normalized-error"), exports);
|
|
19
19
|
__exportStar(require("./errors/db-error"), exports);
|
|
20
20
|
__exportStar(require("./errors/validation-error"), exports);
|
|
21
21
|
__exportStar(require("./errors/not-authorized-error"), exports);
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.errorHandler = void 0;
|
|
7
|
-
const
|
|
4
|
+
const normalized_error_1 = require("../errors/normalized-error");
|
|
8
5
|
const errorHandler = (err, req, res, next) => {
|
|
9
6
|
console.log(err);
|
|
10
|
-
if (err instanceof
|
|
11
|
-
return res.status(err.status).send(err.
|
|
7
|
+
if (err instanceof normalized_error_1.NormalizedError) {
|
|
8
|
+
return res.status(err.status).send(err.serializeErrors());
|
|
12
9
|
}
|
|
13
10
|
return res.status(400).send('Something went wrong');
|
|
14
11
|
};
|
package/package.json
CHANGED