Skip to content

Commit

Permalink
๐Ÿ”ง fix: getAccessToken ๋กœ์ง ์˜ค๋ฅ˜ ์ˆ˜์ •
Browse files Browse the repository at this point in the history
  • Loading branch information
sieunie committed Nov 8, 2024
1 parent d65c70b commit 462c8a1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface AccessTokenInterface {
access_token: string;
access_token_token_expired: string;
token_type: string;
expires_in: number;
}
7 changes: 4 additions & 3 deletions BE/src/koreaInvestment/korea.investment.service.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,19 +13,19 @@ export class KoreaInvestmentService {
return this.accessToken;
}
const response = await axios
.post(getFullURL('/oauth2/tokenP'), {
.post<AccessTokenInterface>(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;
}
Expand Down
4 changes: 2 additions & 2 deletions BE/src/stock/index/stock.index.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class StockIndexService {
},
},
)
.catch((err) => {
.catch(() => {
throw new InternalServerErrorException(
'์ฃผ๊ฐ€ ์ง€์ˆ˜ ์ฐจํŠธ ์ •๋ณด๋ฅผ ์กฐํšŒํ•˜์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค.',
);
Expand All @@ -83,7 +83,7 @@ export class StockIndexService {
},
},
)
.catch((err) => {
.catch(() => {
throw new InternalServerErrorException(
'์ฃผ๊ฐ€ ์ง€์ˆ˜ ๊ฐ’ ์ •๋ณด๋ฅผ ์กฐํšŒํ•˜์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค.',
);
Expand Down

0 comments on commit 462c8a1

Please sign in to comment.