1.0.3 • Published 8 months ago

rpc-http-based-exceptions v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

RPC HTTP Based Exception

A collection of custom RPC Exceptions for NestJS Microservices, standardizing error responses.

You can Basically throw RPC Exceptions that are standard HTTP Exceptions.

Installation

npm i rpc-http-based-exceptions

Usage

@Controller('auth')
export class AuthController {
  constructor(private readonly authService: AuthService) {}

  @MessagePattern({ cmd: 'signin-cmd' })
  async signin(
    @Payload() data: any,
  ): Promise<any> {
    throw new BadRequestRpcException('Password is incorrect')
  }
}

It is mostly useful when you are working with gateway or other services that communicate with RPC, but need Standard HTTP responses.

Available Exceptions

Client errors (4xx):

throw new BadRequestRpcException()
throw new UnauthorizedRpcException()
throw new PaymentRequiredRpcException()
throw new ForbiddenRpcException()
throw new NotFoundRpcException()
throw new MethodNotAllowedRpcException()
throw new NotAcceptableRpcException()
throw new ProxyAuthenticationRequiredRpcException()
throw new RequestTimeoutRpcException()
throw new ConflictRpcException()
throw new GoneRpcException()
throw new LengthRequiredRpcException()
throw new PreconditionFailedRpcException()
throw new PayloadTooLargeRpcException()
throw new URITooLongRpcException()
throw new UnsupportedMediaTypeRpcException()
throw new RangeNotSatisfiableRpcException()
throw new ExpectationFailedRpcException()
throw new ImATeapotRpcException()
throw new MisdirectedRequestRpcException()
throw new UnprocessableEntityRpcException()
throw new LockedRpcException()
throw new FailedDependencyRpcException()
throw new TooEarlyRpcException()
throw new UpgradeRequiredRpcException()
throw new PreconditionRequiredRpcException()
throw new TooManyRequestsRpcException()
throw new RequestHeaderFieldsTooLargeRpcException()
throw new UnavailableForLegalReasonsRpcException()

Server errors (5xx):

throw new InternalServerErrorRpcException()
throw new NotImplementedRpcException()
throw new BadGatewayRpcException()
throw new ServiceUnavailableRpcException()
throw new GatewayTimeoutRpcException()
throw new HTTPVersionNotSupportedRpcException()
throw new VariantAlsoNegotiatesRpcException()
throw new InsufficientStorageRpcException()
throw new LoopDetectedRpcException()
throw new NotExtendedRpcException()
throw new NetworkAuthenticationRequiredRpcException()
1.0.3

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago