@nest-yalc-2/errors 2.2.9 → 2.2.11

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.
Files changed (37) hide show
  1. package/README.md +37 -37
  2. package/{src → dist/src}/__tests__/http-exception.filter.spec.ts +1 -1
  3. package/{src → dist/src}/__tests__/validation-exception.filter.spec.ts +1 -1
  4. package/{src → dist/src}/filters/http-exception.filter.d.ts +4 -3
  5. package/{src → dist/src}/filters/http-exception.filter.js +3 -2
  6. package/dist/src/filters/http-exception.filter.js.map +1 -0
  7. package/{src → dist/src}/filters/http-exception.filter.ts +145 -144
  8. package/{src → dist/src}/filters/validation-exception.filter.d.ts +1 -1
  9. package/{src → dist/src}/filters/validation-exception.filter.js +1 -1
  10. package/dist/src/filters/validation-exception.filter.js.map +1 -0
  11. package/{src → dist/src}/filters/validation-exception.filter.ts +1 -1
  12. package/dist/src/index.d.ts +2 -0
  13. package/dist/src/index.js +3 -0
  14. package/{src → dist/src}/index.js.map +1 -1
  15. package/dist/src/index.ts +4 -0
  16. package/package.json +40 -49
  17. package/LICENSE +0 -661
  18. package/src/filters/http-exception.filter.js.map +0 -1
  19. package/src/filters/validation-exception.filter.js.map +0 -1
  20. package/src/index.d.ts +0 -6
  21. package/src/index.js +0 -7
  22. package/src/index.ts +0 -8
  23. /package/{src → dist/src}/__tests__/database-exception.filter.spec.ts +0 -0
  24. /package/{src → dist/src}/__tests__/system-exception.filter.spec.ts +0 -0
  25. /package/{src → dist/src}/__tests__/tsconfig.json +0 -0
  26. /package/{src → dist/src}/filters/database-exception.filter.d.ts +0 -0
  27. /package/{src → dist/src}/filters/database-exception.filter.js +0 -0
  28. /package/{src → dist/src}/filters/database-exception.filter.js.map +0 -0
  29. /package/{src → dist/src}/filters/database-exception.filter.ts +0 -0
  30. /package/{src → dist/src}/filters/index.d.ts +0 -0
  31. /package/{src → dist/src}/filters/index.js +0 -0
  32. /package/{src → dist/src}/filters/index.js.map +0 -0
  33. /package/{src → dist/src}/filters/index.ts +0 -0
  34. /package/{src → dist/src}/filters/system-exception.filter.d.ts +0 -0
  35. /package/{src → dist/src}/filters/system-exception.filter.js +0 -0
  36. /package/{src → dist/src}/filters/system-exception.filter.js.map +0 -0
  37. /package/{src → dist/src}/filters/system-exception.filter.ts +0 -0
package/README.md CHANGED
@@ -1,37 +1,37 @@
1
- # @nest-yalc-2/errors
2
-
3
- Typed application errors and Result helpers for YALC and NestJS applications.
4
-
5
- Use this package with `@nest-yalc-2/event-manager` when you need errors that
6
- can carry safe client responses, internal diagnostics, structured data, HTTP
7
- status codes, and logging metadata.
8
-
9
- ## Installation
10
-
11
- ```bash
12
- npm install @nest-yalc-2/errors
13
- ```
14
-
15
- ## Main Exports
16
-
17
- - `DefaultError` and HTTP-aware subclasses.
18
- - Error enums and result helpers.
19
- - `MissingArgumentsError` re-exported from CrudGen for compatibility.
20
-
21
- ## Example
22
-
23
- ```ts
24
- import { BadRequestError } from '@nest-yalc-2/errors';
25
-
26
- throw new BadRequestError('user.invalidEmail', {
27
- response: { message: 'Invalid email address.' },
28
- data: { field: 'email' },
29
- });
30
- ```
31
-
32
- ## Documentation
33
-
34
- - Error handling guide:
35
- https://github.com/Nek97/nestjs-yalc/blob/dev/docs/error-handling.md
36
- - DefaultError library:
37
- https://github.com/Nek97/nestjs-yalc/blob/dev/docs/errors.md
1
+ <div align="center">
2
+ <h1>@nest-yalc-2/errors</h1>
3
+ <p><em></em></p>
4
+
5
+ [![npm version](https://badge.fury.io/js/%40nest-yalc-2%2Ferrors.svg)](https://badge.fury.io/js/%40nest-yalc-2%2Ferrors)
6
+ [![License](https://img.shields.io/npm/l/%40nest-yalc-2%2Ferrors.svg)](https://github.com/AI-Autistic-Intelligence)
7
+ </div>
8
+
9
+ ## 📖 Overview
10
+
11
+ **@nest-yalc-2/errors** is a core enterprise module of the [Ferrox Ecosystem](https://ferrox-rust.dev).
12
+
13
+
14
+ > ⚠️ **Note:** This package is a foundational component of the enterprise Ferrox/YALC microservice architecture. For comprehensive documentation, architecture patterns, and ecosystem comparisons across Node, Rust, Python, and PHP, please visit the [Official Documentation Portal](https://ferrox-rust.dev).
15
+
16
+ ## 🚀 Installation
17
+
18
+ \\ash
19
+ npm install @nest-yalc-2/errors
20
+ # or
21
+ yarn add @nest-yalc-2/errors
22
+ # or
23
+ pnpm add @nest-yalc-2/errors
24
+ \
25
+ ## 📚 Ecosystem Documentation
26
+
27
+ Instead of fragmented READMEs, we maintain a centralized, highly structured documentation platform. For deep dives, API references, and full usage examples across the entire stack, refer to the official portal:
28
+
29
+ 👉 **[Explore the Ferrox Documentation](https://ferrox-rust.dev)**
30
+
31
+ ## 🛡️ Security & Enterprise Support
32
+
33
+ This module adheres to the Ferrox Zero-Trust security architecture. If you find any security vulnerabilities, please do NOT open a public issue. Reach out directly to the security team.
34
+
35
+ ## 📄 License
36
+
37
+ Maintained by the Ferrox Enterprise Architecture team.
@@ -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) {
@@ -0,0 +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,mBAAmB,EACnB,WAAW,GAEZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,qBAAqB,EAAE,MAAM,kDAAkD,CAAC;AACzF,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,0CAA0C,CAAC;AAC/E,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,WAAW,GACf,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC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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;
@@ -0,0 +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;AAEzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAKlD,IAAM,yBAAyB,GAA/B,MAAM,yBAAyB;IACpC,YAAoB,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;IAE7C,KAAK,CAAC,KAAY;QAChB,MAAM,QAAQ,GAAG,IAAI,oBAAoB,CACxB,KAAM,CAAC,aAAa,EACnC,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE,CACzC,CAAC;QACF,QAAQ,CAAC,KAAK,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
 
@@ -0,0 +1,2 @@
1
+ export { MissingArgumentsError } from '@nest-yalc-2/crud-gen';
2
+ export * from './filters/index.js';
@@ -0,0 +1,3 @@
1
+ export { MissingArgumentsError } from '@nest-yalc-2/crud-gen';
2
+ export * from './filters/index.js';
3
+ //# sourceMappingURL=index.js.map
@@ -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"}
@@ -0,0 +1,4 @@
1
+ /* istanbul ignore file */
2
+
3
+ export { MissingArgumentsError } from '@nest-yalc-2/crud-gen';
4
+ export * from './filters/index.js';
package/package.json CHANGED
@@ -1,49 +1,40 @@
1
- {
2
- "name": "@nest-yalc-2/errors",
3
- "version": "2.2.9",
4
- "type": "module",
5
- "description": "",
6
- "main": "./src/index.js",
7
- "exports": {
8
- ".": "./src/index.js",
9
- "./*": "./src/*"
10
- },
11
- "author": "Autistic_Intelligence",
12
- "license": "MIT",
13
- "types": "./src/index.d.ts",
14
- "files": [
15
- "dist",
16
- "src"
17
- ],
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",
23
- "axios": "^1.20.0",
24
- "neverthrow": "^8.2.0",
25
- "tslib": "^2.8.1"
26
- },
27
- "peerDependencies": {
28
- "@nestjs/common": "^12.0.0"
29
- },
30
- "keywords": [
31
- "nestjs",
32
- "nestjs-yalc",
33
- "yalc",
34
- "errors",
35
- "framework",
36
- "utility"
37
- ],
38
- "repository": {
39
- "type": "git",
40
- "url": "git+https://github.com/Nek97/nestjs-yalc.git"
41
- },
42
- "bugs": {
43
- "url": "https://github.com/Nek97/nestjs-yalc/issues"
44
- },
45
- "homepage": "https://github.com/Nek97/nestjs-yalc#readme",
46
- "publishConfig": {
47
- "access": "public"
48
- }
49
- }
1
+ {
2
+ "name": "@nest-yalc-2/errors",
3
+ "version": "2.2.11",
4
+ "type": "module",
5
+ "description": "",
6
+ "main": "./dist/src/index.js",
7
+ "exports": {
8
+ ".": "./dist/src/index.js",
9
+ "./*": "./dist/src/*"
10
+ },
11
+ "scripts": {
12
+ "test": "echo \"Error: no test specified\" && exit 1"
13
+ },
14
+ "author": "Autistic_Intelligence",
15
+ "license": "MIT",
16
+ "types": "./dist/src/index.d.ts",
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "dependencies": {
21
+ "@nest-yalc-2/crud-gen": "*",
22
+ "@nest-yalc-2/event-manager": "*",
23
+ "@nest-yalc-2/logger": "*",
24
+ "@nest-yalc-2/utils": "*",
25
+ "axios": "^1.20.0",
26
+ "neverthrow": "^8.2.0",
27
+ "tslib": "^2.8.1"
28
+ },
29
+ "peerDependencies": {
30
+ "@nestjs/common": "^12.0.0"
31
+ },
32
+ "keywords": [
33
+ "nestjs",
34
+ "nestjs-yalc",
35
+ "yalc",
36
+ "errors",
37
+ "framework",
38
+ "utility"
39
+ ]
40
+ }