From 131e82b4c5f94cc23e86149ed42a6167a32cfba1 Mon Sep 17 00:00:00 2001 From: Gabriel Rosa Date: Tue, 29 Nov 2022 09:47:19 -0300 Subject: [PATCH] FIX: connection details improvements --- docsfera.json | 4 +- src/modules/connection/client.service.ts | 42 +++---------------- .../connection/connection.controller.ts | 3 ++ src/utils/ErrorBuilder.ts | 10 +++++ src/utils/errorCodes.ts | 5 +++ 5 files changed, 26 insertions(+), 38 deletions(-) diff --git a/docsfera.json b/docsfera.json index d55f290..55212a4 100644 --- a/docsfera.json +++ b/docsfera.json @@ -3214,9 +3214,9 @@ } }, "info": { - "title": "Maestro - main", + "title": "Maestro - stg2", "description": "Documentation for Maestro gateway", - "version": "25.11.2022 - 18:20", + "version": "29.11.2022 - 9:15", "contact": {} }, "tags": [], diff --git a/src/modules/connection/client.service.ts b/src/modules/connection/client.service.ts index 241296b..7cb416d 100644 --- a/src/modules/connection/client.service.ts +++ b/src/modules/connection/client.service.ts @@ -1,9 +1,4 @@ -import { - OnModuleInit, - Inject, - HttpException, - HttpStatus, -} from '@nestjs/common'; +import { OnModuleInit, Inject } from '@nestjs/common'; import { ClientGrpc } from '@nestjs/microservices'; import { ConnectionManager } from '@dadosfera/protospack-v2'; import { lastValueFrom } from 'rxjs'; @@ -86,12 +81,7 @@ export class ConnectionClientService implements OnModuleInit { }, metadata, ), - ).catch((err) => { - throw new HttpException( - err.details, - err.code === 6 ? HttpStatus.CONFLICT : 400, - ); - }); + ); } async updateConnection( @@ -112,12 +102,7 @@ export class ConnectionClientService implements OnModuleInit { }, metadata, ), - ).catch((err) => { - throw new HttpException( - err.details, - err.code === 6 ? HttpStatus.CONFLICT : 400, - ); - }); + ); } async deleteConnection({ body, metadata }): Promise { @@ -130,12 +115,7 @@ export class ConnectionClientService implements OnModuleInit { }, metadata, ), - ).catch((err) => { - throw new HttpException( - err.details, - err.code === 6 ? HttpStatus.CONFLICT : 400, - ); - }); + ); } async getAllConnections({ body, metadata }): Promise { @@ -146,12 +126,7 @@ export class ConnectionClientService implements OnModuleInit { { search, filters: JSON.stringify(filters), size, page }, metadata, ), - ).catch((err) => { - throw new HttpException( - err.details, - err.code === 6 ? HttpStatus.CONFLICT : 400, - ); - }); + ); } async getConnectionDetails({ @@ -162,12 +137,7 @@ export class ConnectionClientService implements OnModuleInit { return lastValueFrom( this.connectionServiceRead.GetConnectionDetails({ id }, metadata), - ).catch((err) => { - throw new HttpException( - err.details, - err.code === 6 ? HttpStatus.CONFLICT : 400, - ); - }); + ); } async INTERNAL_getAllConnections({ diff --git a/src/modules/connection/connection.controller.ts b/src/modules/connection/connection.controller.ts index 1d614bd..a0dfdfe 100644 --- a/src/modules/connection/connection.controller.ts +++ b/src/modules/connection/connection.controller.ts @@ -9,6 +9,7 @@ import { Get, Headers, Query, + UseFilters, } from '@nestjs/common'; import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; import { ConnectionClientService } from './client.service'; @@ -28,8 +29,10 @@ import { } from './dtos/connection'; import { CreateConnectionDto } from './dtos/connection'; import { PackTheMetadata } from 'src/utils/ PackTheMetadata'; +import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter'; const connectionPermissions = PERMISSIONS_GROUPS.CONNECTION.permissions; +@UseFilters(new GrpcToHttpExceptionFilter()) @ApiTags('connections') @ApiBearerAuth() @Authenticated() diff --git a/src/utils/ErrorBuilder.ts b/src/utils/ErrorBuilder.ts index 8b3956e..16567e1 100644 --- a/src/utils/ErrorBuilder.ts +++ b/src/utils/ErrorBuilder.ts @@ -214,6 +214,16 @@ export function EnrichErrorCode(code: string) { message: 'Id encontra-se num formato inválido', code, }; + case ErrorCodes.CONNECTION.NOT_FOUND: + case ErrorCodes.CONNECTION.PLATFORM_NOT_FOUND: + return { + statusCode: HttpStatus.NOT_FOUND, + error: 'Conexão não encontrada', + message: + 'Não encontramos a conexão solicitada. Caso o erro persista, entre em contato com o suporte', + code, + }; + case ErrorCodes.CONNECTION_TEST.ERROR: return { statusCode: HttpStatus.BAD_REQUEST, diff --git a/src/utils/errorCodes.ts b/src/utils/errorCodes.ts index 9abe020..087ddba 100644 --- a/src/utils/errorCodes.ts +++ b/src/utils/errorCodes.ts @@ -60,6 +60,10 @@ const PIPELINE = { const INPUT = { NOT_FOUND: 'INPUT.NOT_FOUND', }; +const CONNECTION = { + NOT_FOUND: 'CONNECTION.NOT_FOUND', + PLATFORM_NOT_FOUND: 'CONNECTION.PLATFORM_NOT_FOUND', +}; const TRANSFORMATION = { NOT_FOUND: 'TRANSFORMATION.NOT_FOUND', }; @@ -77,6 +81,7 @@ const ErrorCodes = { PIPELINE, INPUT, TRANSFORMATION, + CONNECTION, }; export default ErrorCodes;