@atls/nestjs-connectrpc-errors 0.0.1
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/CHANGELOG.md +29 -0
- package/dist/exception-factories/assertion.exception-factory.d.ts +3 -0
- package/dist/exception-factories/assertion.exception-factory.js +4 -0
- package/dist/exception-factories/domain.expection-factory.d.ts +3 -0
- package/dist/exception-factories/domain.expection-factory.js +10 -0
- package/dist/exception-factories/guard.exception-factory.d.ts +3 -0
- package/dist/exception-factories/guard.exception-factory.js +16 -0
- package/dist/exception-factories/index.d.ts +4 -0
- package/dist/exception-factories/index.js +4 -0
- package/dist/exception-factories/validation.exception-factory.d.ts +3 -0
- package/dist/exception-factories/validation.exception-factory.js +30 -0
- package/dist/exception-filters/connectrpc.exception-filter.d.ts +6 -0
- package/dist/exception-filters/connectrpc.exception-filter.js +37 -0
- package/dist/exception-filters/index.d.ts +1 -0
- package/dist/exception-filters/index.js +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/package.json +78 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
## [0.0.1](https://github.com/atls/nestjs/compare/@atls/nestjs-connectrpc-errors@0.0.0...@atls/nestjs-connectrpc-errors@0.0.1) (2025-01-24)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
* **nestjs:** update grpc reflection ([#341](https://github.com/atls/nestjs/issues/341)) ([3f78e26](https://github.com/atls/nestjs/commit/3f78e26340b9ba64eab425160e8cea7ba83a3538))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# [0.0.0](https://github.com/atls/nestjs/compare/@atls/nestjs-connectrpc-errors@0.0.0...@atls/nestjs-connectrpc-errors@0.0.0) (2025-01-24)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
* **nestjs:** update grpc reflection ([#341](https://github.com/atls/nestjs/issues/341)) ([3f78e26](https://github.com/atls/nestjs/commit/3f78e26340b9ba64eab425160e8cea7ba83a3538))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# 0.0.0 (2025-01-22)
|
|
26
|
+
|
|
27
|
+
### Features
|
|
28
|
+
|
|
29
|
+
- **connectrpc:** init ([#339](https://github.com/atls/nestjs/issues/339)) ([663389c](https://github.com/atls/nestjs/commit/663389cd20156a9c10e93d6dbb8326bf8dcac781))
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Code } from '@connectrpc/connect';
|
|
2
|
+
import { ConnectError } from '@connectrpc/connect';
|
|
3
|
+
import { RpcException } from '@nestjs/microservices';
|
|
4
|
+
export const assertionExceptionFactory = (error) => new RpcException(new ConnectError(error.message, Code.InvalidArgument));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Code } from '@connectrpc/connect';
|
|
2
|
+
import { ConnectError } from '@connectrpc/connect';
|
|
3
|
+
import { RpcException } from '@nestjs/microservices';
|
|
4
|
+
export const domainExceptionFactory = (error) => {
|
|
5
|
+
const logicalError = new LogicalError({
|
|
6
|
+
id: error.id,
|
|
7
|
+
message: error.message,
|
|
8
|
+
});
|
|
9
|
+
return new RpcException(new ConnectError('Logical Error', Code.InvalidArgument, undefined, [logicalError]));
|
|
10
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Code } from '@connectrpc/connect';
|
|
2
|
+
import { ConnectError } from '@connectrpc/connect';
|
|
3
|
+
import { RpcException } from '@nestjs/microservices';
|
|
4
|
+
export const guardExceptionFactory = (errors) => {
|
|
5
|
+
const validationErrors = errors.errors.map((error) => new ValidationError({
|
|
6
|
+
id: error.code,
|
|
7
|
+
property: error.parameter,
|
|
8
|
+
messages: [
|
|
9
|
+
new ValidationErrorMessage({
|
|
10
|
+
id: error.code,
|
|
11
|
+
constraint: error.message,
|
|
12
|
+
}),
|
|
13
|
+
],
|
|
14
|
+
}));
|
|
15
|
+
return new RpcException(new ConnectError('Request validation failed', Code.InvalidArgument, undefined, validationErrors));
|
|
16
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Code } from '@connectrpc/connect';
|
|
2
|
+
import { ConnectError } from '@connectrpc/connect';
|
|
3
|
+
import { RpcException } from '@nestjs/microservices';
|
|
4
|
+
const traverseErrors = (errors = [], callback = () => { }, path = []) => {
|
|
5
|
+
errors.forEach((error) => {
|
|
6
|
+
const currentPath = [...path, error.property];
|
|
7
|
+
if (error.constraints) {
|
|
8
|
+
callback(error, currentPath.join('.'), error.property);
|
|
9
|
+
}
|
|
10
|
+
traverseErrors(error.children, callback, currentPath);
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
export const validationExceptionFactory = (errors) => {
|
|
14
|
+
const validationErrors = [];
|
|
15
|
+
traverseErrors(errors, (error, id, property) => {
|
|
16
|
+
const messages = Object.keys(error.constraints || {}).map((constraintId) => {
|
|
17
|
+
const validationErrorMessage = new ValidationErrorMessage({
|
|
18
|
+
id: constraintId,
|
|
19
|
+
constraint: error.constraints[constraintId],
|
|
20
|
+
});
|
|
21
|
+
return validationErrorMessage;
|
|
22
|
+
});
|
|
23
|
+
validationErrors.push(new ValidationError({
|
|
24
|
+
id,
|
|
25
|
+
property,
|
|
26
|
+
messages,
|
|
27
|
+
}));
|
|
28
|
+
});
|
|
29
|
+
return new RpcException(new ConnectError('Request validation failed', Code.InvalidArgument, undefined, validationErrors));
|
|
30
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ArgumentsHost } from '@nestjs/common';
|
|
2
|
+
import type { Observable } from 'rxjs';
|
|
3
|
+
import { BaseRpcExceptionFilter } from '@nestjs/microservices';
|
|
4
|
+
export declare class ConnectRpcExceptionsFilter extends BaseRpcExceptionFilter {
|
|
5
|
+
catch(exception: unknown, host: ArgumentsHost): Observable<any>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { AssertionError } from 'node:assert';
|
|
8
|
+
import { DomainError } from '@atls/core-errors';
|
|
9
|
+
import { GuardErrors } from '@atls/guard-clause';
|
|
10
|
+
import { Catch } from '@nestjs/common';
|
|
11
|
+
import { BaseRpcExceptionFilter } from '@nestjs/microservices';
|
|
12
|
+
import { ValidationError } from '@atls/nestjs-validation';
|
|
13
|
+
import { assertionExceptionFactory } from '../exception-factories/index.js';
|
|
14
|
+
import { validationExceptionFactory } from '../exception-factories/index.js';
|
|
15
|
+
import { guardExceptionFactory } from '../exception-factories/index.js';
|
|
16
|
+
import { domainExceptionFactory } from '../exception-factories/index.js';
|
|
17
|
+
let ConnectRpcExceptionsFilter = class ConnectRpcExceptionsFilter extends BaseRpcExceptionFilter {
|
|
18
|
+
catch(exception, host) {
|
|
19
|
+
if (exception instanceof AssertionError) {
|
|
20
|
+
return super.catch(assertionExceptionFactory(exception), host);
|
|
21
|
+
}
|
|
22
|
+
if (exception instanceof DomainError) {
|
|
23
|
+
return super.catch(domainExceptionFactory(exception), host);
|
|
24
|
+
}
|
|
25
|
+
if (exception instanceof GuardErrors) {
|
|
26
|
+
return super.catch(guardExceptionFactory(exception), host);
|
|
27
|
+
}
|
|
28
|
+
if (exception instanceof ValidationError) {
|
|
29
|
+
return super.catch(validationExceptionFactory(exception.errors), host);
|
|
30
|
+
}
|
|
31
|
+
return super.catch(exception, host);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
ConnectRpcExceptionsFilter = __decorate([
|
|
35
|
+
Catch()
|
|
36
|
+
], ConnectRpcExceptionsFilter);
|
|
37
|
+
export { ConnectRpcExceptionsFilter };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './connectrpc.exception-filter.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./connectrpc.exception-filter.js";
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atls/nestjs-connectrpc-errors",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "BSD-3-Clause",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
"./package.json": "./package.json",
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"main": "dist/index.js",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "yarn library build",
|
|
20
|
+
"prepack": "yarn run build",
|
|
21
|
+
"postpack": "rm -rf dist",
|
|
22
|
+
"proto:generate": "buf generate integration/proto"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@atls/core-errors": "^0.0.4",
|
|
26
|
+
"@atls/guard-clause": "^0.0.1",
|
|
27
|
+
"@atls/protobuf-rpc": "^0.0.1"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@atls/nestjs-connectrpc": "0.0.4",
|
|
31
|
+
"@atls/nestjs-validation": "0.0.1",
|
|
32
|
+
"@bufbuild/buf": "^1.42.0",
|
|
33
|
+
"@bufbuild/protobuf": "^1.10.0",
|
|
34
|
+
"@bufbuild/protoc-gen-es": "^1.10.0",
|
|
35
|
+
"@connectrpc/connect": "^1.5.0",
|
|
36
|
+
"@connectrpc/connect-node": "^1.5.0",
|
|
37
|
+
"@connectrpc/protoc-gen-connect-es": "^1.5.0",
|
|
38
|
+
"@jest/globals": "^29.6.0",
|
|
39
|
+
"@nestjs/common": "^10.0.5",
|
|
40
|
+
"@nestjs/core": "^10.0.5",
|
|
41
|
+
"@nestjs/microservices": "^10.0.5",
|
|
42
|
+
"@nestjs/platform-express": "^10.0.5",
|
|
43
|
+
"@nestjs/testing": "^10.0.5",
|
|
44
|
+
"@types/node": "22.5.5",
|
|
45
|
+
"class-transformer": "^0.5.1",
|
|
46
|
+
"class-validator": "^0.14.1",
|
|
47
|
+
"get-port": "^7.1.0",
|
|
48
|
+
"reflect-metadata": "^0.2.2",
|
|
49
|
+
"rxjs": "^7.8.1",
|
|
50
|
+
"supertest": "^6.3.3"
|
|
51
|
+
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"@atls/nestjs-validation": "0.0.1",
|
|
54
|
+
"@bufbuild/protobuf": "^1",
|
|
55
|
+
"@connectrpc/connect": "^1",
|
|
56
|
+
"@nestjs/common": "^10",
|
|
57
|
+
"@nestjs/core": "^10",
|
|
58
|
+
"@nestjs/microservices": "^10",
|
|
59
|
+
"class-transformer": "^0.5",
|
|
60
|
+
"class-validator": "^0.14",
|
|
61
|
+
"reflect-metadata": "^0.2",
|
|
62
|
+
"rxjs": "^7"
|
|
63
|
+
},
|
|
64
|
+
"publishConfig": {
|
|
65
|
+
"exports": {
|
|
66
|
+
"./package.json": "./package.json",
|
|
67
|
+
".": {
|
|
68
|
+
"import": "./dist/index.js",
|
|
69
|
+
"types": "./dist/index.d.ts",
|
|
70
|
+
"default": "./dist/index.js"
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"main": "dist/index.js",
|
|
74
|
+
"typings": "dist/index.d.ts"
|
|
75
|
+
},
|
|
76
|
+
"typecheckSkipLibCheck": true,
|
|
77
|
+
"typings": "dist/index.d.ts"
|
|
78
|
+
}
|