rpc-exception.filter.ts 597 B

1234567891011121314151617
  1. import { Catch, RpcExceptionFilter, ArgumentsHost } from '@nestjs/common';
  2. import { Observable, throwError } from 'rxjs';
  3. import { BaseRpcExceptionFilter, RpcException } from '@nestjs/microservices';
  4. @Catch()
  5. export class AllExceptionsFilter extends BaseRpcExceptionFilter {
  6. catch(exception: any, host: ArgumentsHost) {
  7. return super.catch(exception, host);
  8. }
  9. }
  10. @Catch(RpcException)
  11. export class ExceptionFilter implements RpcExceptionFilter<RpcException> {
  12. catch(exception: RpcException, host: ArgumentsHost): Observable<any> {
  13. return throwError(() => exception.getError());
  14. }
  15. }