@sn1006/common 1.0.9 → 1.0.10

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.
@@ -1,5 +1,5 @@
1
- import CustomError from './custom-error';
2
- export declare class BadRequestError extends CustomError {
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);
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.BadRequestError = void 0;
7
- const custom_error_1 = __importDefault(require("./custom-error"));
8
- class BadRequestError extends custom_error_1.default {
7
+ const normalized_error_1 = __importDefault(require("./normalized-error"));
8
+ class BadRequestError extends normalized_error_1.default {
9
9
  constructor(message) {
10
10
  super(message);
11
11
  this.message = message;
@@ -1,5 +1,5 @@
1
- import CustomError from './custom-error';
2
- export default class DBError extends CustomError {
1
+ import NormalizedError from './normalized-error';
2
+ export default class DBError extends NormalizedError {
3
3
  status: number;
4
4
  constructor();
5
5
  serializeError(): {
@@ -3,8 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const custom_error_1 = __importDefault(require("./custom-error"));
7
- class DBError extends custom_error_1.default {
6
+ const normalized_error_1 = __importDefault(require("./normalized-error"));
7
+ class DBError extends normalized_error_1.default {
8
8
  constructor() {
9
9
  super('Error connecting to DB');
10
10
  this.status = 500;
@@ -1,4 +1,4 @@
1
- declare abstract class CustomError extends Error {
1
+ declare abstract class NormalizedError extends Error {
2
2
  abstract status: number;
3
3
  constructor(message: string);
4
4
  abstract serializeError(): {
@@ -6,4 +6,4 @@ declare abstract class CustomError extends Error {
6
6
  field?: string;
7
7
  }[];
8
8
  }
9
- export default CustomError;
9
+ export default NormalizedError;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // the purpose of this class is to "normalize" errors between services
4
+ class NormalizedError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ Object.setPrototypeOf(this, NormalizedError.prototype);
8
+ }
9
+ }
10
+ exports.default = NormalizedError;
@@ -1,5 +1,5 @@
1
- import CustomError from './custom-error';
2
- export declare class NotAuthorizedError extends CustomError {
1
+ import NormalizedError from './normalized-error';
2
+ export declare class NotAuthorizedError extends NormalizedError {
3
3
  status: number;
4
4
  constructor();
5
5
  serializeError(): {
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.NotAuthorizedError = void 0;
7
- const custom_error_1 = __importDefault(require("./custom-error"));
8
- class NotAuthorizedError extends custom_error_1.default {
7
+ const normalized_error_1 = __importDefault(require("./normalized-error"));
8
+ class NotAuthorizedError extends normalized_error_1.default {
9
9
  constructor() {
10
10
  super('Not authorized');
11
11
  this.status = 401;
@@ -1,5 +1,5 @@
1
- import CustomError from './custom-error';
2
- export declare class NotFoundError extends CustomError {
1
+ import NormalizedError from './normalized-error';
2
+ export declare class NotFoundError extends NormalizedError {
3
3
  status: number;
4
4
  constructor();
5
5
  serializeError(): {
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.NotFoundError = void 0;
7
- const custom_error_1 = __importDefault(require("./custom-error"));
8
- class NotFoundError extends custom_error_1.default {
7
+ const normalized_error_1 = __importDefault(require("./normalized-error"));
8
+ class NotFoundError extends normalized_error_1.default {
9
9
  constructor() {
10
10
  super("Resource not found");
11
11
  this.status = 404;
@@ -1,6 +1,6 @@
1
- import CustomError from './custom-error';
1
+ import NormalizedError from './normalized-error';
2
2
  import { ValidationError } from 'express-validator';
3
- declare class CustomValidationError extends CustomError {
3
+ declare class CustomValidationError extends NormalizedError {
4
4
  errors: ValidationError[];
5
5
  status: number;
6
6
  constructor(errors: ValidationError[]);
@@ -3,10 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const custom_error_1 = __importDefault(require("./custom-error"));
7
- class CustomValidationError extends custom_error_1.default {
6
+ const normalized_error_1 = __importDefault(require("./normalized-error"));
7
+ class CustomValidationError extends normalized_error_1.default {
8
8
  constructor(errors) {
9
- super("Invalid username or password");
9
+ super("Validaton error");
10
10
  this.errors = errors;
11
11
  this.status = 400;
12
12
  Object.setPrototypeOf(this, CustomValidationError.prototype);
package/build/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from './errors/bad-request-error';
2
- export * from './errors/custom-error';
2
+ export * from './errors/normalized-error';
3
3
  export * from './errors/db-error';
4
4
  export * from './errors/validation-error';
5
5
  export * from './errors/not-authorized-error';
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/custom-error"), exports);
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);
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.errorHandler = void 0;
7
- const custom_error_1 = __importDefault(require("../errors/custom-error"));
7
+ const normalized_error_1 = __importDefault(require("../errors/normalized-error"));
8
8
  const errorHandler = (err, req, res, next) => {
9
9
  console.log(err);
10
- if (err instanceof custom_error_1.default) {
10
+ if (err instanceof normalized_error_1.default) {
11
11
  return res.status(err.status).send(err.serializeError());
12
12
  }
13
13
  return res.status(400).send('Something went wrong');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sn1006/common",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class CustomError extends Error {
4
- constructor(message) {
5
- super(message);
6
- Object.setPrototypeOf(this, CustomError.prototype);
7
- }
8
- }
9
- exports.default = CustomError;