From a7ecf0ef9afc5bc3ec862c69fc4c1113768ed260 Mon Sep 17 00:00:00 2001 From: wkddntjr1123 Date: Tue, 13 Dec 2022 17:11:24 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20logger=EC=97=90=20500=EB=8C=80=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=20=EB=B0=8F=20=EC=9D=BC=EB=B0=98=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=EB=A5=BC=20logger=EC=97=90=EC=84=9C=20=EC=9E=A1?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/libs/common/filters/http-exception.filter.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/backend/libs/common/filters/http-exception.filter.ts b/backend/libs/common/filters/http-exception.filter.ts index d958fa33..48feac99 100644 --- a/backend/libs/common/filters/http-exception.filter.ts +++ b/backend/libs/common/filters/http-exception.filter.ts @@ -7,10 +7,12 @@ export class HttpExceptionFilter implements ExceptionFilter { public catch(exception: Error, host: ArgumentsHost) { const ctx = host.switchToHttp(); const response = ctx.getResponse(); - if (!(exception instanceof HttpException)) { + if (!(exception instanceof HttpException) || exception.getStatus() >= 500) { + logger.error(exception); exception = new InternalServerErrorException('Unknown Error'); - logger.error(`${exception.stack}`); + return response.status((exception as HttpException).getStatus()).json((exception as HttpException).getResponse()); } - return response.status((exception as HttpException).getStatus()).json((exception as HttpException).getResponse()); + logger.log(exception); + return response.status(exception.getStatus()).json(exception.getResponse()); } } From f87138237883dabe6628dc019b0f1fc985223a9a Mon Sep 17 00:00:00 2001 From: wkddntjr1123 Date: Tue, 13 Dec 2022 17:12:04 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=EC=83=88=EB=A1=9C=EC=9A=B4=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=20update=EC=8B=9C=20scoreHistory=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=B8=ED=95=B4=20=EB=B0=9C=EC=83=9D=ED=95=98=EB=8D=98=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/user/user.service.ts | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/backend/src/user/user.service.ts b/backend/src/user/user.service.ts index acb6b116..08e5f946 100644 --- a/backend/src/user/user.service.ts +++ b/backend/src/user/user.service.ts @@ -36,13 +36,8 @@ export class UserService { if (!user) { try { user = await this.updateUser(lowerUsername, githubToken); - if (!user.scoreHistory) { - user.scoreHistory = []; - } - user.scoreHistory.push({ date: new Date(), score: user.score }); - user = await this.userRepository.createOrUpdate(user); } catch { - throw new HttpException(`can't update this user.`, HttpStatus.NO_CONTENT); + throw new HttpException(`can't update this user.`, HttpStatus.SERVICE_UNAVAILABLE); } } const { totalRank, tierRank } = @@ -79,18 +74,19 @@ export class UserService { organizations, pinnedRepositories, }; - if (!updatedUser.scoreHistory) { - updatedUser.scoreHistory = []; + + if (!updatedUser?.scoreHistory?.length) { + updatedUser.scoreHistory = [{ date: new Date(), score: updatedUser.score }]; } const KR_TIME_DIFF = 9 * 60 * 60 * 1000; const utc = updatedUser.scoreHistory[updatedUser.scoreHistory.length - 1].date.getTime(); - if (new Date(utc + KR_TIME_DIFF).getDate() == new Date().getDate()) { + if (new Date(utc + KR_TIME_DIFF).getDate() === new Date().getDate()) { updatedUser.scoreHistory.pop(); + updatedUser.scoreHistory.push({ + date: new Date(), + score: updatedUser.score, + }); } - updatedUser.scoreHistory.push({ - date: new Date(), - score: updatedUser.score, - }); if (updatedUser.scoreHistory.length > 1) { updatedUser.scoreDifference = updatedUser.score - updatedUser.scoreHistory[updatedUser.scoreHistory.length - 2].score; @@ -274,7 +270,7 @@ export class UserService { primaryLanguages: Array.from(languagesScore.keys()).slice(0, 3), }; } catch { - throw new HttpException(`can't update this user.`, HttpStatus.NO_CONTENT); + throw new HttpException(`can't update this user.`, HttpStatus.SERVICE_UNAVAILABLE); } }