Skip to content

Commit 375823e

Browse files
committed
[hotfix] 문항 못찾을 때 번호 로깅
1 parent 538a37d commit 375823e

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

src/main/java/com/moplus/moplus_server/client/homefeed/dto/response/HomeFeedResponse.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@
33
import com.moplus.moplus_server.admin.problemset.dto.response.ProblemSetGetResponse;
44
import com.moplus.moplus_server.admin.problemset.dto.response.ProblemSummaryResponse;
55
import com.moplus.moplus_server.client.submit.domain.ProgressStatus;
6+
import com.moplus.moplus_server.global.error.exception.ErrorCode;
7+
import com.moplus.moplus_server.global.error.exception.NotFoundException;
68
import java.time.LocalDate;
79
import java.util.List;
10+
import org.slf4j.Logger;
11+
import org.slf4j.LoggerFactory;
812

913
public record HomeFeedResponse(
1014
List<DailyProgressResponse> dailyProgresses,
1115
List<ProblemSetHomeFeedResponse> problemSets
1216
) {
17+
private static final Logger log = LoggerFactory.getLogger(HomeFeedResponse.class);
18+
1319
public static HomeFeedResponse of(
1420
List<DailyProgressResponse> dailyProgresses,
1521
List<ProblemSetHomeFeedResponse> problemSets
@@ -36,12 +42,20 @@ public record ProblemSetHomeFeedResponse(
3642
public static ProblemSetHomeFeedResponse of(LocalDate date, Long publishId,
3743
ProblemSetGetResponse problemSetGetResponse,
3844
Long submitCount) {
45+
ProblemSummaryResponse problemSummaryResponse = null;
46+
try {
47+
problemSummaryResponse = problemSetGetResponse.problemSummaries().get(0);
48+
} catch (IndexOutOfBoundsException e) {
49+
log.atError().log("id " + publishId + "번 발행에 속한 세트에 문항이 존재하지 않습니다. ");
50+
throw new NotFoundException(ErrorCode.PROBLEM_NOT_FOUND,
51+
"id " + publishId + "번 발행에 속한 세트에 문항이 존재하지 않습니다. ");
52+
}
3953
return new ProblemSetHomeFeedResponse(
4054
date,
4155
publishId,
4256
problemSetGetResponse.title(),
4357
submitCount,
44-
ProblemHomeFeedResponse.of(problemSetGetResponse.problemSummaries().get(0))
58+
ProblemHomeFeedResponse.of(problemSummaryResponse)
4559
);
4660
}
4761

src/main/java/com/moplus/moplus_server/domain/problem/repository/ProblemRepository.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ default void existsByIdElseThrow(Long id) {
2525
Optional<Problem> findByIdWithFetchJoin(@Param("id") Long id);
2626

2727
default Problem findByIdElseThrow(Long id) {
28-
return findById(id).orElseThrow(() -> new NotFoundException(ErrorCode.PROBLEM_NOT_FOUND));
28+
return findById(id).orElseThrow(
29+
() -> new NotFoundException(ErrorCode.PROBLEM_NOT_FOUND, id + "번 문제가 존재하지 않습니다."));
2930
}
3031

3132
default Problem findByIdWithFetchJoinElseThrow(Long id) {

src/main/java/com/moplus/moplus_server/global/error/exception/NotFoundException.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package com.moplus.moplus_server.global.error.exception;
22

3-
public class NotFoundException extends BusinessException{
3+
public class NotFoundException extends BusinessException {
4+
5+
public NotFoundException(ErrorCode errorCode, String message) {
6+
super(message, errorCode);
7+
}
48

59
public NotFoundException(ErrorCode errorCode) {
610
super(errorCode);

0 commit comments

Comments
 (0)