From 462c8a189747ec8e15cb25eec87b8e4936543db3 Mon Sep 17 00:00:00 2001 From: anjdydhody Date: Fri, 8 Nov 2024 11:42:36 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix:=20getAccessToken=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../interface/korea.investment.interface.ts | 6 ++++++ BE/src/koreaInvestment/korea.investment.service.ts | 7 ++++--- BE/src/stock/index/stock.index.service.ts | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 BE/src/koreaInvestment/interface/korea.investment.interface.ts diff --git a/BE/src/koreaInvestment/interface/korea.investment.interface.ts b/BE/src/koreaInvestment/interface/korea.investment.interface.ts new file mode 100644 index 00000000..e290a32c --- /dev/null +++ b/BE/src/koreaInvestment/interface/korea.investment.interface.ts @@ -0,0 +1,6 @@ +export interface AccessTokenInterface { + access_token: string; + access_token_token_expired: string; + token_type: string; + expires_in: number; +} diff --git a/BE/src/koreaInvestment/korea.investment.service.ts b/BE/src/koreaInvestment/korea.investment.service.ts index 886b68cb..727c044c 100644 --- a/BE/src/koreaInvestment/korea.investment.service.ts +++ b/BE/src/koreaInvestment/korea.investment.service.ts @@ -1,6 +1,7 @@ import axios from 'axios'; import { UnauthorizedException } from '@nestjs/common'; import { getFullURL } from '../util/getFullURL'; +import { AccessTokenInterface } from './interface/korea.investment.interface'; export class KoreaInvestmentService { private accessToken: string; @@ -12,19 +13,19 @@ export class KoreaInvestmentService { return this.accessToken; } const response = await axios - .post(getFullURL('/oauth2/tokenP'), { + .post(getFullURL('/oauth2/tokenP'), { grant_type: 'client_credentials', appkey: process.env.KOREA_INVESTMENT_APP_KEY, appsecret: process.env.KOREA_INVESTMENT_APP_SECRET, }) - .catch((err) => { + .catch(() => { throw new UnauthorizedException('액세스 토큰을 조회하지 못했습니다.'); }); const { data } = response; this.accessToken = data.access_token; - this.tokenExpireTime = new Date(Date.now() + +data.expires_in); + this.tokenExpireTime = new Date(data.access_token_token_expired); return this.accessToken; } diff --git a/BE/src/stock/index/stock.index.service.ts b/BE/src/stock/index/stock.index.service.ts index 3a14c7fc..587af43d 100644 --- a/BE/src/stock/index/stock.index.service.ts +++ b/BE/src/stock/index/stock.index.service.ts @@ -59,7 +59,7 @@ export class StockIndexService { }, }, ) - .catch((err) => { + .catch(() => { throw new InternalServerErrorException( '주가 지수 차트 정보를 조회하지 못했습니다.', ); @@ -83,7 +83,7 @@ export class StockIndexService { }, }, ) - .catch((err) => { + .catch(() => { throw new InternalServerErrorException( '주가 지수 값 정보를 조회하지 못했습니다.', );