Skip to content

Commit da2df3a

Browse files
committed
Error handling not found in GRPC_EXCEPTION_FROM_HTTP
1 parent f2683a9 commit da2df3a

File tree

3 files changed

+12
-30
lines changed

3 files changed

+12
-30
lines changed

lib/interceptors/http-to-grpc.interceptor.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import {
66
} from "@nestjs/common";
77
import { Observable, throwError } from "rxjs";
88
import { catchError } from "rxjs/operators";
9-
import { GRPC_EXCEPTION_FROM_HTTP } from "../utils";
9+
import { GRPC_CODE_FROM_HTTP } from "../utils";
10+
import { status as Status } from "@grpc/grpc-js";
11+
import { RpcException } from "@nestjs/microservices";
1012

1113
@Injectable()
1214
export class HttpToGrpcInterceptor implements NestInterceptor {
@@ -32,11 +34,16 @@ export class HttpToGrpcInterceptor implements NestInterceptor {
3234
message: string;
3335
};
3436

35-
if (!(exception.statusCode in GRPC_EXCEPTION_FROM_HTTP))
36-
return throwError(() => err);
37+
const statusCode =
38+
GRPC_CODE_FROM_HTTP[exception.statusCode] || Status.INTERNAL;
3739

38-
const Exception = GRPC_EXCEPTION_FROM_HTTP[exception.statusCode];
39-
return throwError(() => new Exception(exception.message));
40+
return throwError(
41+
() =>
42+
new RpcException({
43+
message: exception.message,
44+
code: statusCode,
45+
}),
46+
);
4047
}),
4148
);
4249
}

lib/utils/grpc-exceptions-map.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

lib/utils/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
export * from "./error-object";
22
export * from "./http-codes-map";
3-
export * from "./grpc-exceptions-map";
43
export * from "./grpc-codes-map";

0 commit comments

Comments
 (0)