Skip to content

Commit

Permalink
fix(aggregator.services): add generic error log when generating user'…
Browse files Browse the repository at this point in the history
…s JWT
  • Loading branch information
LeKer29 committed Feb 25, 2022
1 parent c79b4cb commit de9c2a5
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions src/aggregator/services/budget-insight/budget-insight.client.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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<JWTokenResponse> = 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<JWTokenResponse> = 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);
}
}

/**
Expand Down

0 comments on commit de9c2a5

Please sign in to comment.