FEAT: Connection test creating connection

- If any error occurs, connection is deleted
 - If operation_result is false, connection is deleted
This commit is contained in:
Gabriel Rosa
2022-08-03 11:31:57 -03:00
parent a1cdad42ab
commit 688bf49f3b
11 changed files with 201 additions and 124 deletions
+19 -3
View File
@@ -1,16 +1,32 @@
import { ExceptionFilter, Catch, ArgumentsHost } from '@nestjs/common';
import {
ExceptionFilter,
Catch,
ArgumentsHost,
HttpException,
HttpStatus,
} from '@nestjs/common';
import { Response } from 'express';
import ErrorBuilder from '../utils/ErrorBuilder';
/**
* ExceptionFilter to handle RpcException thrown by our microservices
*
* If it detects that the exception is already an **HttpException** or it is generated by our **ErrorBuilder**,
* it will return the exception without any treatment.
*/
@Catch(Error)
export class GrpcToHttpExceptionFilter implements ExceptionFilter {
catch(exception: any, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const response = ctx.getResponse<Response>();
// return this exception directly if is already of type ErrorBuilder,
// else transform it using the ErrorBuilder
if (exception instanceof HttpException) {
return response
.status(exception.getStatus())
.json(exception.getResponse());
}
const err =
exception.constructor.name === ErrorBuilder.name
? exception