Skip to content

Commit 33358b9

Browse files
authored
Merge pull request #305 from boostcampwm-2022/develop
v0.2.2 배포
2 parents 53ab800 + 54675df commit 33358b9

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

backend/libs/common/filters/http-exception.filter.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ export class HttpExceptionFilter implements ExceptionFilter {
77
public catch(exception: Error, host: ArgumentsHost) {
88
const ctx = host.switchToHttp();
99
const response = ctx.getResponse<Response>();
10-
if (!(exception instanceof HttpException)) {
10+
if (!(exception instanceof HttpException) || exception.getStatus() >= 500) {
11+
logger.error(exception);
1112
exception = new InternalServerErrorException('Unknown Error');
12-
logger.error(`${exception.stack}`);
13+
return response.status((exception as HttpException).getStatus()).json((exception as HttpException).getResponse());
1314
}
14-
return response.status((exception as HttpException).getStatus()).json((exception as HttpException).getResponse());
15+
logger.log(exception);
16+
return response.status(exception.getStatus()).json(exception.getResponse());
1517
}
1618
}

backend/src/user/user.service.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,8 @@ export class UserService {
3636
if (!user) {
3737
try {
3838
user = await this.updateUser(lowerUsername, githubToken);
39-
if (!user.scoreHistory) {
40-
user.scoreHistory = [];
41-
}
42-
user.scoreHistory.push({ date: new Date(), score: user.score });
43-
user = await this.userRepository.createOrUpdate(user);
4439
} catch {
45-
throw new HttpException(`can't update this user.`, HttpStatus.NO_CONTENT);
40+
throw new HttpException(`can't update this user.`, HttpStatus.SERVICE_UNAVAILABLE);
4641
}
4742
}
4843
const { totalRank, tierRank } =
@@ -79,18 +74,19 @@ export class UserService {
7974
organizations,
8075
pinnedRepositories,
8176
};
82-
if (!updatedUser.scoreHistory) {
83-
updatedUser.scoreHistory = [];
77+
78+
if (!updatedUser?.scoreHistory?.length) {
79+
updatedUser.scoreHistory = [{ date: new Date(), score: updatedUser.score }];
8480
}
8581
const KR_TIME_DIFF = 9 * 60 * 60 * 1000;
8682
const utc = updatedUser.scoreHistory[updatedUser.scoreHistory.length - 1].date.getTime();
87-
if (new Date(utc + KR_TIME_DIFF).getDate() == new Date().getDate()) {
83+
if (new Date(utc + KR_TIME_DIFF).getDate() === new Date().getDate()) {
8884
updatedUser.scoreHistory.pop();
85+
updatedUser.scoreHistory.push({
86+
date: new Date(),
87+
score: updatedUser.score,
88+
});
8989
}
90-
updatedUser.scoreHistory.push({
91-
date: new Date(),
92-
score: updatedUser.score,
93-
});
9490
if (updatedUser.scoreHistory.length > 1) {
9591
updatedUser.scoreDifference =
9692
updatedUser.score - updatedUser.scoreHistory[updatedUser.scoreHistory.length - 2].score;
@@ -274,7 +270,7 @@ export class UserService {
274270
primaryLanguages: Array.from(languagesScore.keys()).slice(0, 3),
275271
};
276272
} catch {
277-
throw new HttpException(`can't update this user.`, HttpStatus.NO_CONTENT);
273+
throw new HttpException(`can't update this user.`, HttpStatus.SERVICE_UNAVAILABLE);
278274
}
279275
}
280276

0 commit comments

Comments
 (0)