Skip to content

Commit 0d383c2

Browse files
committed
Create grpc-exceptions-map.ts for GRPC_EXCEPTION_FROM_HTTP
1 parent ddb0a14 commit 0d383c2

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

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

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,12 @@
11
import {
22
CallHandler,
33
ExecutionContext,
4-
HttpStatus,
54
Injectable,
65
NestInterceptor,
76
} from "@nestjs/common";
87
import { Observable, throwError } from "rxjs";
98
import { catchError } from "rxjs/operators";
10-
import {
11-
GrpcAbortedException,
12-
GrpcAlreadyExistsException,
13-
GrpcInternalException,
14-
GrpcInvalidArgumentException,
15-
GrpcNotFoundException,
16-
GrpcPermissionDeniedException,
17-
GrpcResourceExhaustedException,
18-
GrpcUnauthenticatedException,
19-
GrpcUnknownException,
20-
} from "../exceptions";
21-
22-
const GRPC_EXCEPTION_FROM_HTTP: Record<number, any> = {
23-
[HttpStatus.NOT_FOUND]: GrpcNotFoundException,
24-
[HttpStatus.FORBIDDEN]: GrpcPermissionDeniedException,
25-
[HttpStatus.METHOD_NOT_ALLOWED]: GrpcAbortedException,
26-
[HttpStatus.INTERNAL_SERVER_ERROR]: GrpcInternalException,
27-
[HttpStatus.TOO_MANY_REQUESTS]: GrpcResourceExhaustedException,
28-
[HttpStatus.BAD_GATEWAY]: GrpcUnknownException,
29-
[HttpStatus.CONFLICT]: GrpcAlreadyExistsException,
30-
[HttpStatus.UNPROCESSABLE_ENTITY]: GrpcInvalidArgumentException,
31-
[HttpStatus.UNAUTHORIZED]: GrpcUnauthenticatedException,
32-
};
9+
import { GRPC_EXCEPTION_FROM_HTTP } from "../utils";
3310

3411
@Injectable()
3512
export class HttpToGrpcInterceptor implements NestInterceptor {

lib/utils/grpc-exceptions-map.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { HttpStatus } from "@nestjs/common";
2+
import {
3+
GrpcAbortedException,
4+
GrpcAlreadyExistsException,
5+
GrpcInternalException,
6+
GrpcInvalidArgumentException,
7+
GrpcNotFoundException,
8+
GrpcPermissionDeniedException,
9+
GrpcResourceExhaustedException,
10+
GrpcUnauthenticatedException,
11+
GrpcUnknownException,
12+
} from "../exceptions";
13+
14+
export const GRPC_EXCEPTION_FROM_HTTP: Record<number, any> = {
15+
[HttpStatus.NOT_FOUND]: GrpcNotFoundException,
16+
[HttpStatus.FORBIDDEN]: GrpcPermissionDeniedException,
17+
[HttpStatus.METHOD_NOT_ALLOWED]: GrpcAbortedException,
18+
[HttpStatus.INTERNAL_SERVER_ERROR]: GrpcInternalException,
19+
[HttpStatus.TOO_MANY_REQUESTS]: GrpcResourceExhaustedException,
20+
[HttpStatus.BAD_GATEWAY]: GrpcUnknownException,
21+
[HttpStatus.CONFLICT]: GrpcAlreadyExistsException,
22+
[HttpStatus.UNPROCESSABLE_ENTITY]: GrpcInvalidArgumentException,
23+
[HttpStatus.UNAUTHORIZED]: GrpcUnauthenticatedException,
24+
};

lib/utils/index.ts

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

0 commit comments

Comments
 (0)