pangea-server 1.0.73 → 1.0.74

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.
@@ -303,15 +303,15 @@ async function handleDbError(operation) {
303
303
  }
304
304
  catch (err) {
305
305
  if (err instanceof sequelize_1.UniqueConstraintError) {
306
- helpers_1.AppError.Throw({ statusCodeName: 'BAD_REQUEST', errorCode: 'DUPLICATE_KEY', err });
306
+ helpers_1.AppError.Throw({ statusCodeName: 'BAD_REQUEST', errorCode: 'DUPLICATE_KEY', originalError: err });
307
307
  }
308
308
  if (err instanceof sequelize_1.ForeignKeyConstraintError) {
309
309
  const originalErr = err.original;
310
310
  if (originalErr.errno === 1451) {
311
- helpers_1.AppError.Throw({ statusCodeName: 'CONFLICT', errorCode: 'MODELS_ASSOCIATED', err });
311
+ helpers_1.AppError.Throw({ statusCodeName: 'CONFLICT', errorCode: 'MODELS_ASSOCIATED', originalError: err });
312
312
  }
313
313
  if (originalErr.errno === 1452) {
314
- helpers_1.AppError.Throw({ statusCodeName: 'BAD_REQUEST', errorCode: 'FOREIGN_KEY_INTEGRITY', err });
314
+ helpers_1.AppError.Throw({ statusCodeName: 'BAD_REQUEST', errorCode: 'FOREIGN_KEY_INTEGRITY', originalError: err });
315
315
  }
316
316
  }
317
317
  throw err;
@@ -2,15 +2,13 @@ import type { StatusCodeName, StatusCode, ErrorCode } from '../types/error.types
2
2
  type AppErrorCtor = {
3
3
  statusCodeName: StatusCodeName;
4
4
  errorCode: ErrorCode;
5
- err?: Error;
6
- message?: string;
5
+ originalError?: Error;
7
6
  };
8
7
  export declare class AppError extends Error {
9
8
  name: string;
10
9
  statusCode: StatusCode;
11
10
  errorCode: ErrorCode;
12
11
  originalError?: Error;
13
- message: string;
14
12
  constructor(config: AppErrorCtor);
15
13
  static Throw(config: AppErrorCtor): never;
16
14
  static ThrowEntityNotFound(): never;
@@ -4,14 +4,11 @@ exports.AppError = void 0;
4
4
  const http_status_codes_1 = require("http-status-codes");
5
5
  class AppError extends Error {
6
6
  constructor(config) {
7
- super();
7
+ super(config.originalError?.message);
8
8
  this.name = 'AppError';
9
- const { statusCodeName, errorCode, err, message } = config;
10
- this.statusCode = http_status_codes_1.StatusCodes[statusCodeName];
11
- this.errorCode = errorCode;
12
- if (err)
13
- this.originalError = err;
14
- this.message = message || err?.message || errorCode;
9
+ this.statusCode = http_status_codes_1.StatusCodes[config.statusCodeName];
10
+ this.errorCode = config.errorCode;
11
+ this.originalError = config.originalError;
15
12
  }
16
13
  static Throw(config) {
17
14
  throw new AppError(config);
@@ -20,10 +17,10 @@ class AppError extends Error {
20
17
  this.Throw({ statusCodeName: 'NOT_FOUND', errorCode: 'ENTITY_NOT_FOUND' });
21
18
  }
22
19
  static ThrowUnauthorized() {
23
- this.Throw({ statusCodeName: 'UNAUTHORIZED', errorCode: 'UNAUTHORIZED', message: 'Unauthorized access' });
20
+ this.Throw({ statusCodeName: 'UNAUTHORIZED', errorCode: 'UNAUTHORIZED' });
24
21
  }
25
22
  static ThrowInvalidCredentials() {
26
- this.Throw({ statusCodeName: 'UNAUTHORIZED', errorCode: 'INVALID_CREDENTIALS', message: 'Invalid credentials' });
23
+ this.Throw({ statusCodeName: 'UNAUTHORIZED', errorCode: 'INVALID_CREDENTIALS' });
27
24
  }
28
25
  }
29
26
  exports.AppError = AppError;
@@ -14,7 +14,7 @@ function validateRequest(validate, req) {
14
14
  return validate(input);
15
15
  }
16
16
  catch (err) {
17
- helpers_1.AppError.Throw({ statusCodeName: 'BAD_REQUEST', errorCode: 'INVALID_INPUT_DATA', err: err });
17
+ helpers_1.AppError.Throw({ statusCodeName: 'BAD_REQUEST', errorCode: 'INVALID_INPUT_DATA', originalError: err });
18
18
  }
19
19
  }
20
20
  exports.validateRequest = validateRequest;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pangea-server",
3
3
  "description": "",
4
- "version": "1.0.73",
4
+ "version": "1.0.74",
5
5
  "files": [
6
6
  "dist"
7
7
  ],