Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nestjs-grpc-exceptions

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nestjs-grpc-exceptions - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

lib/utils/grpc-codes-map.ts

6

CHANGELOG.md
# nestjs-grpc-exceptions
## 0.2.2
### Patch Changes
- fbea997: refactor the internal handler
## 0.2.1

@@ -4,0 +10,0 @@

40

lib/interceptors/http-to-grpc.interceptor.ts
import {
CallHandler,
ExecutionContext,
HttpStatus,
Injectable,

@@ -10,26 +9,6 @@ NestInterceptor,

import { catchError } from "rxjs/operators";
import {
GrpcAbortedException,
GrpcAlreadyExistsException,
GrpcInternalException,
GrpcInvalidArgumentException,
GrpcNotFoundException,
GrpcPermissionDeniedException,
GrpcResourceExhaustedException,
GrpcUnauthenticatedException,
GrpcUnknownException,
} from "../exceptions";
import { GRPC_CODE_FROM_HTTP } from "../utils";
import { status as Status } from "@grpc/grpc-js";
import { RpcException } from "@nestjs/microservices";
const GRPC_EXCEPTION_FROM_HTTP: Record<number, any> = {
[HttpStatus.NOT_FOUND]: GrpcNotFoundException,
[HttpStatus.FORBIDDEN]: GrpcPermissionDeniedException,
[HttpStatus.METHOD_NOT_ALLOWED]: GrpcAbortedException,
[HttpStatus.INTERNAL_SERVER_ERROR]: GrpcInternalException,
[HttpStatus.TOO_MANY_REQUESTS]: GrpcResourceExhaustedException,
[HttpStatus.BAD_GATEWAY]: GrpcUnknownException,
[HttpStatus.CONFLICT]: GrpcAlreadyExistsException,
[HttpStatus.UNPROCESSABLE_ENTITY]: GrpcInvalidArgumentException,
[HttpStatus.UNAUTHORIZED]: GrpcUnauthenticatedException,
};
@Injectable()

@@ -59,7 +38,12 @@ export class HttpToGrpcInterceptor implements NestInterceptor {

if (!(exception.statusCode in GRPC_EXCEPTION_FROM_HTTP))
return throwError(() => err);
const statusCode =
GRPC_CODE_FROM_HTTP[exception.statusCode] || Status.INTERNAL;
const Exception = GRPC_EXCEPTION_FROM_HTTP[exception.statusCode];
return throwError(() => new Exception(exception.message));
return throwError(
() =>
new RpcException({
message: exception.message,
code: statusCode,
}),
);
}),

@@ -66,0 +50,0 @@ );

export * from "./error-object";
export * from "./http-codes-map";
export * from "./grpc-codes-map";

@@ -14,3 +14,3 @@ {

},
"version": "0.2.1",
"version": "0.2.2",
"main": "dist/index.js",

@@ -17,0 +17,0 @@ "module": "dist/index.mjs",

@@ -1,2 +0,2 @@

import { HttpException } from "@nestjs/common";
import { HttpException, HttpStatus } from "@nestjs/common";
import { Observable, throwError } from "rxjs";

@@ -51,3 +51,3 @@ import { GrpcNotFoundException, GrpcToHttpInterceptor } from "../../lib";

expect(err).toBeInstanceOf(HttpException);
expect(err.status).toEqual(404);
expect(err.status).toEqual(HttpStatus.NOT_FOUND);
done();

@@ -54,0 +54,0 @@ },

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc