From de9c2a5eeb6ce2078089a11cbe008715ff594a5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KERGUTUIL=20Th=C3=A9o?= <58176270+LeKer29@users.noreply.github.com> Date: Fri, 25 Feb 2022 10:40:08 +0100 Subject: [PATCH] fix(aggregator.services): add generic error log when generating user's JWT --- .../budget-insight/budget-insight.client.ts | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/src/aggregator/services/budget-insight/budget-insight.client.ts b/src/aggregator/services/budget-insight/budget-insight.client.ts index a1b839dd..f69dd5f8 100644 --- a/src/aggregator/services/budget-insight/budget-insight.client.ts +++ b/src/aggregator/services/budget-insight/budget-insight.client.ts @@ -1,6 +1,6 @@ import { URL } from 'url'; import { HttpService } from '@nestjs/axios'; -import { Injectable, Logger } from '@nestjs/common'; +import { Injectable, Logger, UnauthorizedException } from '@nestjs/common'; import * as moment from 'moment-timezone'; import { AxiosResponse, AxiosRequestConfig, AxiosError } from 'axios'; import { config } from 'node-config-ts'; @@ -112,25 +112,30 @@ export class BudgetInsightClient { const url: string = `${biConfig.baseUrl}/auth/jwt`; this.logger.debug(`Get a user JWT on ${url}`); - const resp: AxiosResponse = await this.toPromise( - this.httpService.post( - url, - { - client_id: biConfig.clientId, - client_secret: biConfig.clientSecret, - // eslint-disable-next-line no-null/no-null - id_user: userId ?? null, - }, - { - headers: { - 'Content-Type': 'application/json', - Accept: 'application/json', + try { + const resp: AxiosResponse = await this.toPromise( + this.httpService.post( + url, + { + client_id: biConfig.clientId, + client_secret: biConfig.clientSecret, + // eslint-disable-next-line no-null/no-null + id_user: userId ?? null, }, - }, - ), - ); - - return resp.data; + { + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json', + }, + }, + ), + ); + + return resp.data; + } catch (err) { + this.logger.error("An error occurred when generating user's JWT token"); + throw new UnauthorizedException(err); + } } /**