https://i.sstatic.net/sUGm1.png
There seems to be an issue with this microservice,
If I throw an exception in the users Service
, it should be returned back to the gateway and then to the client
However, this is not happening! The client only sees the default 500
server error
I have applied RPC exception filters in both the client and users services
rpc-exception.filter.ts
import { Catch, RpcExceptionFilter, ArgumentsHost } from '@nestjs/common';
import { Observable, throwError } from 'rxjs';
import { RpcException } from '@nestjs/microservices';
@Catch(RpcException)
export class MicroserviceExceptionFilter implements RpcExceptionFilter<RpcException> {
catch(exception: RpcException, host: ArgumentsHost): Observable<any> {
return throwError(() => exception.getError());
}
}
And here is the code for the main gateway file main.ts
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const environmentService = app.get(EnvironmentService);
app.useGlobalFilters(new MicroserviceExceptionFilter());
await app.listen(environmentService.getAppPort());
}
bootstrap();
So, how can I effectively display exceptions that occur in a service to the user?