nestjs-grpc-exceptions
Advanced tools
Comparing version 0.0.1 to 0.1.0
# nestjs-grpc-exceptions | ||
## 0.1.0 | ||
### Minor Changes | ||
- 5b7dbb2: add grpc to http interceptor | ||
## 0.0.1 | ||
@@ -4,0 +10,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { RpcExceptionFilter } from '@nestjs/common'; | ||
import { RpcExceptionFilter, ExceptionFilter, ArgumentsHost, NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common'; | ||
import { RpcException } from '@nestjs/microservices'; | ||
@@ -9,2 +9,6 @@ import { Observable } from 'rxjs'; | ||
declare class GrpcHttpExceptionFilter implements ExceptionFilter { | ||
catch(exception: any, host: ArgumentsHost): void; | ||
} | ||
declare class GrpcNotFoundException extends RpcException { | ||
@@ -54,2 +58,6 @@ constructor(error: string | object); | ||
export { GrpcAbortedException, GrpcAlreadyExistsException, GrpcCancelledException, GrpcInternalException, GrpcInvalidArgumentException, GrpcNotFoundException, GrpcPermissionDeniedException, GrpcResourceExhaustedException, GrpcServerExceptionFilter, GrpcUnauthenticatedException, GrpcUnavailableException, GrpcUnknownException }; | ||
declare class GrpcToHttpInterceptor implements NestInterceptor { | ||
intercept(_context: ExecutionContext, next: CallHandler<any>): Observable<any> | Promise<Observable<any>>; | ||
} | ||
export { GrpcAbortedException, GrpcAlreadyExistsException, GrpcCancelledException, GrpcHttpExceptionFilter, GrpcInternalException, GrpcInvalidArgumentException, GrpcNotFoundException, GrpcPermissionDeniedException, GrpcResourceExhaustedException, GrpcServerExceptionFilter, GrpcToHttpInterceptor, GrpcUnauthenticatedException, GrpcUnavailableException, GrpcUnknownException }; |
export * from "./grpc-server-exception.filter"; | ||
export * from "./grpc-http-exception.filter"; |
export * from "./filters"; | ||
export * from "./exceptions"; | ||
export * from "./interceptors"; |
import type { status as GrpcStatusCode } from "@grpc/grpc-js"; | ||
import { RpcException } from "@nestjs/microservices"; | ||
@@ -22,2 +23,3 @@ export type GrpcExceptionPayload = { | ||
type: typeof error === "string" ? "string" : "object", | ||
exceptionName: RpcException.name, | ||
}), | ||
@@ -24,0 +26,0 @@ code, |
export * from "./error-object"; | ||
export * from "./http-codes-map"; |
@@ -6,10 +6,14 @@ { | ||
"author": "Mohsen Bostan <mohsenbostandev@gmail.com", | ||
"version": "0.0.1", | ||
"homepage": "https://github.com/mohsenbostan/nestjs-grpc-exceptions", | ||
"bugs": { | ||
"url": "https://github.com/mohsenbostan/nestjs-grpc-exceptions/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/mohsenbostan/nestjs-grpc-exceptions.git" | ||
}, | ||
"version": "0.1.0", | ||
"main": "dist/index.js", | ||
"module": "dist/index.mjs", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
"build": "tsup index.ts --format cjs,esm --dts", | ||
"lint": "tsc" | ||
}, | ||
"devDependencies": { | ||
@@ -31,3 +35,7 @@ "@changesets/cli": "^2.26.0", | ||
"@nestjs/microservices": "^8.0.0 || ^9.0.0" | ||
}, | ||
"scripts": { | ||
"build": "tsup index.ts --format cjs,esm --dts", | ||
"lint": "tsc" | ||
} | ||
} | ||
} |
@@ -43,5 +43,20 @@ # NestJS gRPC Exceptions | ||
Now you can use the exception classes: | ||
Add the client interceptor to your client: | ||
```ts | ||
import { GrpcToHttpInterceptor } from 'nestjs-grpc-exceptions'; | ||
@Get(':id') | ||
@UseInterceptors(GrpcToHttpInterceptor) | ||
function findUser(@Param('id') id: number): void; | ||
``` | ||
Now you can use the exception classes in your servers: | ||
```ts | ||
import { | ||
GrpcNotFoundException, | ||
GrpcInvalidArgumentException, | ||
} from "nestjs-grpc-exceptions"; | ||
throw new GrpcNotFoundException("User Not Found."); | ||
@@ -48,0 +63,0 @@ throw new GrpcInvalidArgumentException("input 'name' is not valid."); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
833087
33
20674
0
1
68
0