@nest-yalc-2/errors 2.2.9 → 2.2.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nest-yalc-2/errors",
3
- "version": "2.2.9",
3
+ "version": "2.2.10",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "./src/index.js",
@@ -16,10 +16,10 @@
16
16
  "src"
17
17
  ],
18
18
  "dependencies": {
19
- "@nest-yalc-2/crud-gen": "^2.2.9",
20
- "@nest-yalc-2/event-manager": "^2.2.9",
21
- "@nest-yalc-2/logger": "^2.2.9",
22
- "@nest-yalc-2/utils": "^2.2.9",
19
+ "@nest-yalc-2/crud-gen": "^2.2.10",
20
+ "@nest-yalc-2/event-manager": "^2.2.10",
21
+ "@nest-yalc-2/logger": "^2.2.10",
22
+ "@nest-yalc-2/utils": "^2.2.10",
23
23
  "axios": "^1.20.0",
24
24
  "neverthrow": "^8.2.0",
25
25
  "tslib": "^2.8.1"
@@ -11,7 +11,7 @@ import {
11
11
  } from '@nestjs/common';
12
12
  import { HttpExceptionFilter } from '../filters/http-exception.filter.js';
13
13
  import { GqlError } from '@nest-yalc-2/graphql/plugins/gql.error.js';
14
- import { DefaultError } from '../index.js';
14
+ import { DefaultError } from '@node-yalc/errors';
15
15
  import { GqlArgumentsHost } from '@nestjs/graphql';
16
16
  describe('Http exceptions filter', () => {
17
17
  let filter: HttpExceptionFilter;
@@ -11,7 +11,7 @@ import {
11
11
  import { createMock } from '@golevelup/ts-jest';
12
12
  import { LoggerService } from '@nestjs/common';
13
13
  import { ValidationExceptionFilter } from '../filters/validation-exception.filter.js';
14
- import { InputValidationError } from '../index.js';
14
+ import { InputValidationError } from '@node-yalc/errors';
15
15
  import { CrudGenError } from '@nest-yalc-2/crud-gen/crud-gen.error.js';
16
16
 
17
17
  describe('ValidationExceptionFilter', () => {
@@ -1,17 +1,18 @@
1
1
  import { GqlExceptionFilter } from '@nestjs/graphql';
2
2
  import * as common from '@nestjs/common';
3
3
  import type { HttpServer } from '@nestjs/common';
4
- import { DefaultErrorMixin, MissingArgumentsError } from '@nest-yalc-2/errors';
4
+ import { IAbstractDefaultError } from '@node-yalc/errors';
5
+ import { MissingArgumentsError } from '@nest-yalc-2/crud-gen/missing-arguments.error.js';
5
6
  import { FastifyReply as FResponse } from 'fastify';
6
7
  import { GqlError } from '@nest-yalc-2/graphql/plugins/gql.error.js';
7
8
  import { BaseExceptionFilter } from '@nestjs/core';
8
9
  import { type ImprovedLoggerService } from '@node-yalc/logger/logger-abstract.service.js';
9
- type HttpErrorType = common.HttpException | MissingArgumentsError | GqlError | DefaultErrorMixin;
10
+ type HttpErrorType = common.HttpException | MissingArgumentsError | GqlError | IAbstractDefaultError;
10
11
  export declare class HttpExceptionFilter extends BaseExceptionFilter implements GqlExceptionFilter, common.ExceptionFilter {
11
12
  protected logger: ImprovedLoggerService;
12
13
  constructor(logger: ImprovedLoggerService, applicationRef?: HttpServer);
13
14
  catch(error: Error | HttpErrorType, host: common.ArgumentsHost, { sendResponse }?: {
14
15
  sendResponse: boolean;
15
- }): Error | FResponse<import("fastify").RouteGenericInterface, import("fastify").RawServerDefault, import("node:http").IncomingMessage, import("node:http").ServerResponse<import("node:http").IncomingMessage>, unknown, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown> | import("@nest-yalc-2/errors").IAbstractDefaultError;
16
+ }): Error | FResponse<import("fastify").RouteGenericInterface, import("fastify").RawServerDefault, import("node:http").IncomingMessage, import("node:http").ServerResponse<import("node:http").IncomingMessage>, unknown, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown> | IAbstractDefaultError;
16
17
  }
17
18
  export {};
@@ -1,10 +1,11 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
2
  import * as common from '@nestjs/common';
3
- import { DefaultErrorMixin, MissingArgumentsError, isDefaultErrorMixin, formatCause, } from '@nest-yalc-2/errors';
3
+ import { DefaultErrorMixin, isDefaultErrorMixin, formatCause, } from '@node-yalc/errors';
4
+ import { MissingArgumentsError } from '@nest-yalc-2/crud-gen/missing-arguments.error.js';
4
5
  import { isEntityError, } from '@nest-yalc-2/crud-gen/entity.error.js';
5
6
  import { GqlError } from '@nest-yalc-2/graphql/plugins/gql.error.js';
6
7
  import { BaseExceptionFilter } from '@nestjs/core';
7
- import { getLogLevelByStatus } from '../../../event-manager/src/event.helper.js';
8
+ import { getLogLevelByStatus } from '@node-yalc/event-manager/event.helper.js';
8
9
  import { LogLevelEnum } from '@node-yalc/logger/logger.enum.js';
9
10
  let HttpExceptionFilter = class HttpExceptionFilter extends BaseExceptionFilter {
10
11
  constructor(logger, applicationRef) {
@@ -1 +1 @@
1
- {"version":3,"file":"http-exception.filter.js","sourceRoot":"","sources":["http-exception.filter.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,MAAM,MAAM,gBAAgB,CAAC;AAEzC,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,mBAAmB,EACnB,WAAW,GACZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAEL,aAAa,GACd,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EAAE,QAAQ,EAAE,MAAM,2CAA2C,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAWzD,IAAM,mBAAmB,GAAzB,MAAM,mBACX,SAAQ,mBAAmB;IAG3B,YACY,MAA6B,EACvC,cAA2B;QAE3B,KAAK,CAAC,cAAc,CAAC,CAAC;QAHZ,WAAM,GAAN,MAAM,CAAuB;IAIzC,CAAC;IAED,KAAK,CACH,KAA4B,EAC5B,IAA0B,EAC1B,EAAE,YAAY,KAAgC,EAAE,YAAY,EAAE,IAAI,EAAE;QAEpE,IAAI,CAAC;YACH,MAAM,W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AAC,UAAU,CAAC,qBAAqB,CAAC;oBACrD,IAAI,WAAW;wBAAE,MAAM,GAAI,KAA8B,CAAC,SAAS,EAAE,CAAC;oBACtE,OAAO,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;gBACrD,CAAC;YACH,CAAC;QACH,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YAEX,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACnB,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAA;AAnHY,mBAAmB;IAN/B,MAAM,CAAC,KAAK,CACX,MAAM,CAAC,aAAa,EACpB,qBAAqB,EACrB,QAAQ,EACR,iBAAiB,CAClB;;GACY,mBAAmB,CAmH/B"}
@@ -1,144 +1,145 @@
1
- import { GqlExceptionFilter } from '@nestjs/graphql';
2
- import * as common from '@nestjs/common';
3
- import type { HttpServer } from '@nestjs/common';
4
- import {
5
- DefaultErrorMixin,
6
- MissingArgumentsError,
7
- isDefaultErrorMixin,
8
- formatCause,
9
- } from '@nest-yalc-2/errors';
10
- import {
11
- EntityError,
12
- isEntityError,
13
- } from '@nest-yalc-2/crud-gen/entity.error.js';
14
- import { FastifyReply as FResponse } from 'fastify';
15
- import { GqlError } from '@nest-yalc-2/graphql/plugins/gql.error.js';
16
- import { BaseExceptionFilter } from '@nestjs/core';
17
- import { getLogLevelByStatus } from '../../../event-manager/src/event.helper.js';
18
- import { LogLevelEnum } from '@node-yalc/logger/logger.enum.js';
19
- import { type ImprovedLoggerService } from '@node-yalc/logger/logger-abstract.service.js';
20
-
21
- type HttpErrorType =
22
- common.HttpException | MissingArgumentsError | GqlError | DefaultErrorMixin;
23
- @common.Catch(
24
- common.HttpException,
25
- MissingArgumentsError,
26
- GqlError,
27
- DefaultErrorMixin,
28
- )
29
- export class HttpExceptionFilter
30
- extends BaseExceptionFilter
31
- implements GqlExceptionFilter, common.ExceptionFilter
32
- {
33
- constructor(
34
- protected logger: ImprovedLoggerService,
35
- applicationRef?: HttpServer,
36
- ) {
37
- super(applicationRef);
38
- }
39
-
40
- catch(
41
- error: Error | HttpErrorType,
42
- host: common.ArgumentsHost,
43
- { sendResponse }: { sendResponse: boolean } = { sendResponse: true },
44
- ) {
45
- try {
46
- const isHttpError =
47
- this.isHttpError(error) || error instanceof common.HttpException;
48
- // TODO: Validate when monitoring is in place if we need an eventEmitter here instead of log
49
- switch (true) {
50
- // Base logging for normal operation execution errors
51
- case error instanceof MissingArgumentsError:
52
- this.logger.log(error.message, {
53
- stack: error.stack,
54
- });
55
- break;
56
-
57
- case isDefaultErrorMixin(error):
58
- // no need to log, DefaultErrorMixin already logs
59
- break;
60
-
61
- /**
62
- * Log original error message (for now only if is an EntityError)
63
- * @todo refactor with the default error mixin
64
- */
65
- case isEntityError(error):
66
- {
67
- const entityError = error as EntityError;
68
- this.logger.error(
69
- entityError.originalError?.message
70
- ? entityError.originalError.message
71
- : error,
72
- entityError.originalError?.stack,
73
- {
74
- stack: entityError.originalError?.stack,
75
- data: {
76
- response: entityError.getResponse(),
77
- name: entityError.name,
78
- cause: formatCause(entityError.cause),
79
- },
80
- },
81
- );
82
- }
83
- break;
84
-
85
- case isHttpError:
86
- {
87
- const httpError = error as common.HttpException;
88
- const logLevel = getLogLevelByStatus(httpError.getStatus());
89
-
90
- if (logLevel === LogLevelEnum.ERROR) {
91
- this.logger[logLevel](error.message, error.stack, {
92
- stack: httpError.stack,
93
- data: {
94
- response: httpError.getResponse(),
95
- name: error.name,
96
- cause: formatCause(error.cause),
97
- },
98
- });
99
- } else {
100
- this.logger[logLevel](error.message, {
101
- stack: error.stack,
102
- data: {
103
- response: httpError.getResponse(),
104
- name: error.name,
105
- cause: formatCause(error.cause),
106
- },
107
- });
108
- }
109
- }
110
- break;
111
-
112
- case error instanceof GqlError:
113
- this.logger.error((<GqlError>error).systemMessage ?? error.message);
114
- break;
115
-
116
- // Log critically any other error, as those are not expected
117
- default:
118
- this.logger.error(error.message, error.stack, {
119
- stack: error.stack,
120
- data: {
121
- cause: formatCause(error.cause),
122
- name: error.name,
123
- },
124
- });
125
- break;
126
- }
127
-
128
- if (host.getType() === 'http') {
129
- if (sendResponse) {
130
- const ctx = host.switchToHttp();
131
- const response = ctx.getResponse<FResponse>();
132
- let status = common.HttpStatus.INTERNAL_SERVER_ERROR;
133
- if (isHttpError) status = (error as common.HttpException).getStatus();
134
- return response.status(status).send(error.message);
135
- }
136
- }
137
- } catch (e) {
138
- // eslint-disable-next-line no-console
139
- console.error(e); // if there's an error with the logger itself
140
- }
141
-
142
- return error;
143
- }
144
- }
1
+ import { GqlExceptionFilter } from '@nestjs/graphql';
2
+ import * as common from '@nestjs/common';
3
+ import type { HttpServer } from '@nestjs/common';
4
+ import {
5
+ DefaultErrorMixin,
6
+ isDefaultErrorMixin,
7
+ formatCause,
8
+ IAbstractDefaultError,
9
+ } from '@node-yalc/errors';
10
+ import { MissingArgumentsError } from '@nest-yalc-2/crud-gen/missing-arguments.error.js';
11
+ import {
12
+ EntityError,
13
+ isEntityError,
14
+ } from '@nest-yalc-2/crud-gen/entity.error.js';
15
+ import { FastifyReply as FResponse } from 'fastify';
16
+ import { GqlError } from '@nest-yalc-2/graphql/plugins/gql.error.js';
17
+ import { BaseExceptionFilter } from '@nestjs/core';
18
+ import { getLogLevelByStatus } from '@node-yalc/event-manager/event.helper.js';
19
+ import { LogLevelEnum } from '@node-yalc/logger/logger.enum.js';
20
+ import { type ImprovedLoggerService } from '@node-yalc/logger/logger-abstract.service.js';
21
+
22
+ type HttpErrorType =
23
+ common.HttpException | MissingArgumentsError | GqlError | IAbstractDefaultError;
24
+ @common.Catch(
25
+ common.HttpException,
26
+ MissingArgumentsError,
27
+ GqlError,
28
+ DefaultErrorMixin,
29
+ )
30
+ export class HttpExceptionFilter
31
+ extends BaseExceptionFilter
32
+ implements GqlExceptionFilter, common.ExceptionFilter
33
+ {
34
+ constructor(
35
+ protected logger: ImprovedLoggerService,
36
+ applicationRef?: HttpServer,
37
+ ) {
38
+ super(applicationRef);
39
+ }
40
+
41
+ catch(
42
+ error: Error | HttpErrorType,
43
+ host: common.ArgumentsHost,
44
+ { sendResponse }: { sendResponse: boolean } = { sendResponse: true },
45
+ ) {
46
+ try {
47
+ const isHttpError =
48
+ this.isHttpError(error) || error instanceof common.HttpException;
49
+ // TODO: Validate when monitoring is in place if we need an eventEmitter here instead of log
50
+ switch (true) {
51
+ // Base logging for normal operation execution errors
52
+ case error instanceof MissingArgumentsError:
53
+ this.logger.log(error.message, {
54
+ stack: error.stack,
55
+ });
56
+ break;
57
+
58
+ case isDefaultErrorMixin(error):
59
+ // no need to log, DefaultErrorMixin already logs
60
+ break;
61
+
62
+ /**
63
+ * Log original error message (for now only if is an EntityError)
64
+ * @todo refactor with the default error mixin
65
+ */
66
+ case isEntityError(error):
67
+ {
68
+ const entityError = error as EntityError;
69
+ this.logger.error(
70
+ entityError.originalError?.message
71
+ ? entityError.originalError.message
72
+ : error,
73
+ entityError.originalError?.stack,
74
+ {
75
+ stack: entityError.originalError?.stack,
76
+ data: {
77
+ response: entityError.getResponse(),
78
+ name: entityError.name,
79
+ cause: formatCause(entityError.cause),
80
+ },
81
+ },
82
+ );
83
+ }
84
+ break;
85
+
86
+ case isHttpError:
87
+ {
88
+ const httpError = error as common.HttpException;
89
+ const logLevel = getLogLevelByStatus(httpError.getStatus());
90
+
91
+ if (logLevel === LogLevelEnum.ERROR) {
92
+ (this.logger as any)[logLevel](error.message, error.stack, {
93
+ stack: httpError.stack,
94
+ data: {
95
+ response: httpError.getResponse(),
96
+ name: error.name,
97
+ cause: formatCause(error.cause),
98
+ },
99
+ });
100
+ } else {
101
+ (this.logger as any)[logLevel](error.message, {
102
+ stack: error.stack,
103
+ data: {
104
+ response: httpError.getResponse(),
105
+ name: error.name,
106
+ cause: formatCause(error.cause),
107
+ },
108
+ });
109
+ }
110
+ }
111
+ break;
112
+
113
+ case error instanceof GqlError:
114
+ this.logger.error((<GqlError>error).systemMessage ?? error.message);
115
+ break;
116
+
117
+ // Log critically any other error, as those are not expected
118
+ default:
119
+ this.logger.error(error.message, error.stack, {
120
+ stack: error.stack,
121
+ data: {
122
+ cause: formatCause(error.cause),
123
+ name: error.name,
124
+ },
125
+ });
126
+ break;
127
+ }
128
+
129
+ if (host.getType() === 'http') {
130
+ if (sendResponse) {
131
+ const ctx = host.switchToHttp();
132
+ const response = ctx.getResponse<FResponse>();
133
+ let status = common.HttpStatus.INTERNAL_SERVER_ERROR;
134
+ if (isHttpError) status = (error as common.HttpException).getStatus();
135
+ return response.status(status).send(error.message);
136
+ }
137
+ }
138
+ } catch (e) {
139
+ // eslint-disable-next-line no-console
140
+ console.error(e); // if there's an error with the logger itself
141
+ }
142
+
143
+ return error;
144
+ }
145
+ }
@@ -1,5 +1,5 @@
1
1
  import { GqlExceptionFilter } from '@nestjs/graphql';
2
- import { InputValidationError } from '../index.js';
2
+ import { InputValidationError } from '@node-yalc/errors';
3
3
  import type { LoggerService } from '@nestjs/common';
4
4
  export declare class ValidationExceptionFilter implements GqlExceptionFilter {
5
5
  private logger;
@@ -2,7 +2,7 @@ import { __decorate, __metadata } from "tslib";
2
2
  import { CrudGenError } from '@nest-yalc-2/crud-gen/crud-gen.error.js';
3
3
  import { UUIDValidationError } from '@nest-yalc-2/graphql/scalars/uuid-validation.error.js';
4
4
  import * as common from '@nestjs/common';
5
- import { InputValidationError } from '../index.js';
5
+ import { InputValidationError } from '@node-yalc/errors';
6
6
  let ValidationExceptionFilter = class ValidationExceptionFilter {
7
7
  constructor(logger) {
8
8
  this.logger = logger;
@@ -1 +1 @@
1
- {"version":3,"file":"validation-exception.filter.js","sourceRoot":"","sources":["validation-exception.filter.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AACvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uDAAuD,CAAC;AAC5F,OAAO,KAAK,MAAM,MAAM,gBAAgB,CAAC;AAE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,GAAG,KAAK,CAAC,KAAK,CAAC;QAC7B,IAAI,CAAC,MAAM,CAAC,KAAK,CACA,KAAM,CAAC,aAAa,IAAI,QAAQ,CAAC,OAAO,EACvD,QAAQ,CAAC,KAAK,CACf,CAAC;QAEF,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAA;AAhBY,yBAAyB;IADrC,MAAM,CAAC,KAAK,CAAC,mBAAmB,EAAE,YAAY,CAAC;;GACnC,yBAAyB,CAgBrC"}
@@ -2,7 +2,7 @@ import { CrudGenError } from '@nest-yalc-2/crud-gen/crud-gen.error.js';
2
2
  import { UUIDValidationError } from '@nest-yalc-2/graphql/scalars/uuid-validation.error.js';
3
3
  import * as common from '@nestjs/common';
4
4
  import { GqlExceptionFilter } from '@nestjs/graphql';
5
- import { InputValidationError } from '../index.js';
5
+ import { InputValidationError } from '@node-yalc/errors';
6
6
 
7
7
  import type { LoggerService } from '@nestjs/common';
8
8
 
package/src/index.d.ts CHANGED
@@ -1,6 +1,2 @@
1
1
  export { MissingArgumentsError } from '@nest-yalc-2/crud-gen';
2
- export * from '@node-yalc/errors/error.enum.js';
3
- export * from '@node-yalc/errors/error.class.js';
4
- export * from '@node-yalc/errors/default.error.js';
5
- export * from '@node-yalc/errors/result.error.js';
6
2
  export * from './filters/index.js';
package/src/index.js CHANGED
@@ -1,7 +1,3 @@
1
1
  export { MissingArgumentsError } from '@nest-yalc-2/crud-gen';
2
- export * from '@node-yalc/errors/error.enum.js';
3
- export * from '@node-yalc/errors/error.class.js';
4
- export * from '@node-yalc/errors/default.error.js';
5
- export * from '@node-yalc/errors/result.error.js';
6
2
  export * from './filters/index.js';
7
3
  //# sourceMappingURL=index.js.map
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,cAAc,iCAAiC,CAAC;AAChD,cAAc,kCAAkC,CAAC;AACjD,cAAc,oCAAoC,CAAC;AACnD,cAAc,mCAAmC,CAAC;AAClD,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,cAAc,oBAAoB,CAAC"}
package/src/index.ts CHANGED
@@ -1,8 +1,4 @@
1
1
  /* istanbul ignore file */
2
2
 
3
3
  export { MissingArgumentsError } from '@nest-yalc-2/crud-gen';
4
- export * from '@node-yalc/errors/error.enum.js';
5
- export * from '@node-yalc/errors/error.class.js';
6
- export * from '@node-yalc/errors/default.error.js';
7
- export * from '@node-yalc/errors/result.error.js';
8
4
  export * from './filters/index.js';