From 93a3fe021ac70216ae01d3549c6be577118805a5 Mon Sep 17 00:00:00 2001 From: Mirkuz Date: Tue, 9 Apr 2024 11:48:30 +0200 Subject: [PATCH 1/5] fix: add try catch for JSON parse --- lib/interceptors/grpc-to-http.interceptor.ts | 32 +++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/lib/interceptors/grpc-to-http.interceptor.ts b/lib/interceptors/grpc-to-http.interceptor.ts index 5d741a7..b3219d8 100644 --- a/lib/interceptors/grpc-to-http.interceptor.ts +++ b/lib/interceptors/grpc-to-http.interceptor.ts @@ -29,18 +29,34 @@ export class GrpcToHttpInterceptor implements NestInterceptor { ) return throwError(() => err); - const exception = JSON.parse(err.details) as { - error: string | object; - type: string; - exceptionName: string; - }; + const statusCode = + HTTP_CODE_FROM_GRPC[err.code] || HttpStatus.INTERNAL_SERVER_ERROR; + + let exception: { exceptionName: any; error: any; type?: string }; + try { + exception = JSON.parse(err.details) as { + error: string | object; + type: string; + exceptionName: string; + }; + } catch (parseError) { + return throwError( + () => + new HttpException( + { + message: err.details, + statusCode, + error: HttpStatus[statusCode], + }, + statusCode, + { cause: err }, + ), + ); + } if (exception.exceptionName !== RpcException.name) return throwError(() => err); - const statusCode = - HTTP_CODE_FROM_GRPC[err.code] || HttpStatus.INTERNAL_SERVER_ERROR; - return throwError( () => new HttpException( From 3063b68c80381dccbb9fbbba12c2948fa94de5f5 Mon Sep 17 00:00:00 2001 From: Mirkuz Date: Tue, 9 Apr 2024 12:19:41 +0200 Subject: [PATCH 2/5] Version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8600a02..1392d6d 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "type": "git", "url": "https://github.com/mohsenbostan/nestjs-grpc-exceptions.git" }, - "version": "0.2.2", + "version": "0.0.1", "main": "dist/index.js", "module": "dist/index.mjs", "types": "dist/index.d.ts", From 09844a22bedba9f59cb404630a3eeb65dcdf3129 Mon Sep 17 00:00:00 2001 From: Mirkuz Date: Tue, 9 Apr 2024 12:40:01 +0200 Subject: [PATCH 3/5] Version --- CHANGELOG.md | 26 +------------------------- package.json | 2 +- 2 files changed, 2 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71bcd3f..10cc0fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,35 +1,11 @@ # nestjs-grpc-exceptions -## 0.2.2 +## 0.0.2 ### Patch Changes - fbea997: refactor the internal handler -## 0.2.1 - -### Patch Changes - -- ea24504: support NestJS version 10 - -## 0.2.0 - -### Minor Changes - -- b03aad4: Add Http to gRPC interceptor - -## 0.1.1 - -### Patch Changes - -- b3c4b70: fix client interceptor gRPC code - -## 0.1.0 - -### Minor Changes - -- 5b7dbb2: add grpc to http interceptor - ## 0.0.1 ### Patch Changes diff --git a/package.json b/package.json index 1392d6d..640e330 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "type": "git", "url": "https://github.com/mohsenbostan/nestjs-grpc-exceptions.git" }, - "version": "0.0.1", + "version": "0.0.2", "main": "dist/index.js", "module": "dist/index.mjs", "types": "dist/index.d.ts", From ddb542708937b60443bcf6a754864f9af1809053 Mon Sep 17 00:00:00 2001 From: Mirkuz Date: Thu, 11 Apr 2024 10:28:03 +0200 Subject: [PATCH 4/5] Revert "Version" This reverts commit 09844a22bedba9f59cb404630a3eeb65dcdf3129. --- CHANGELOG.md | 26 +++++++++++++++++++++++++- package.json | 2 +- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10cc0fa..71bcd3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,35 @@ # nestjs-grpc-exceptions -## 0.0.2 +## 0.2.2 ### Patch Changes - fbea997: refactor the internal handler +## 0.2.1 + +### Patch Changes + +- ea24504: support NestJS version 10 + +## 0.2.0 + +### Minor Changes + +- b03aad4: Add Http to gRPC interceptor + +## 0.1.1 + +### Patch Changes + +- b3c4b70: fix client interceptor gRPC code + +## 0.1.0 + +### Minor Changes + +- 5b7dbb2: add grpc to http interceptor + ## 0.0.1 ### Patch Changes diff --git a/package.json b/package.json index 640e330..1392d6d 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "type": "git", "url": "https://github.com/mohsenbostan/nestjs-grpc-exceptions.git" }, - "version": "0.0.2", + "version": "0.0.1", "main": "dist/index.js", "module": "dist/index.mjs", "types": "dist/index.d.ts", From ec472e4bbe82275a1ccd68c99507f4d5f052caef Mon Sep 17 00:00:00 2001 From: Mirkuz Date: Thu, 11 Apr 2024 10:28:07 +0200 Subject: [PATCH 5/5] Revert "Version" This reverts commit 3063b68c80381dccbb9fbbba12c2948fa94de5f5. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1392d6d..8600a02 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "type": "git", "url": "https://github.com/mohsenbostan/nestjs-grpc-exceptions.git" }, - "version": "0.0.1", + "version": "0.2.2", "main": "dist/index.js", "module": "dist/index.mjs", "types": "dist/index.d.ts",