Skip to content

Commit

Permalink
Merge pull request #24 from softeerbootcamp4th/refactor/arrivalEvent
Browse files Browse the repository at this point in the history
[Refactor] quiz exception 및 에러 logger 추가
  • Loading branch information
eckrin authored Aug 19, 2024
2 parents 858f634 + ee25e29 commit 07a3e3f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public enum ErrorCode {
USERNAME_EXISTS_ERROR(false, HttpStatus.BAD_REQUEST.value(), "이미 존재하는 닉네임입니다."),

//event_arrival
PHONENUM_EXISTS_ERROR(false, HttpStatus.BAD_REQUEST.value(),"이미 응모한 전화번호입니다.")
PHONENUM_EXISTS_ERROR(false, HttpStatus.BAD_REQUEST.value(),"이미 응모한 전화번호입니다."),
QUIZ_NOT_FOUND(false, HttpStatus.NOT_FOUND.value(), "오늘 날짜에 퀴즈가 없습니다.")
;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public CompletableFuture<CommonResponse<ArrivalApplicationResponseDto>> arrivalE
if(ex.getCause() instanceof ExistingUserException) {
throw new ExistingUserException("[비동기 에러] 유저가 이미 존재합니다.");
} else {
log.error("Exception occurred while arrival application", ex);
throw new AsyncRequestExecuteException("[비동기 에러] 선착순 요청 중 서버 오류 발생");
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ public CommonResponse<?> asyncRequestExecuteException(AsyncRequestExecuteExcepti
return new CommonResponse<>(ErrorCode.INTERNAL_SERVER_ERROR);
}

@ExceptionHandler(DailyQuizNotExistsException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
public CommonResponse<?> dailyQuizNotFoundException(DailyQuizNotExistsException e, HttpServletRequest request) {
log.warn("ARRIVAL-003> 요청 URI: " + request.getRequestURI() + ", 에러 메세지: " + e.getMessage());
return new CommonResponse<>(ErrorCode.QUIZ_NOT_FOUND);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
import java.util.List;

public interface EventRewardRepository extends JpaRepository<EventReward, Long> {
int countByEvent(Event event);
List<EventReward> findAllByEvent(Event event);
List<EventReward> findAllByEvent(Event event);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.softeer.podoarrival.event.service;

import com.softeer.podoarrival.event.exception.DailyQuizNotExistsException;
import com.softeer.podoarrival.event.model.dto.GetQuizResponseDto;
import com.softeer.podoarrival.event.model.entity.Quiz;
import com.softeer.podoarrival.event.repository.QuizRepository;
Expand Down Expand Up @@ -43,9 +44,9 @@ public GetQuizResponseDto getQuizInfo() {
// cache miss
if(quizDto.isInvalid()) {
Quiz quiz = quizRepository.findByEventDate(LocalDate.now());
if(quiz == null) {throw new DailyQuizNotExistsException("오늘 날짜에는 퀴즈가 존재하지 않습니다.");}
setQuizToRedis(quiz);
return QuizMapper.mapQuizToGetQuizResponseDto(quiz);

}
// cache hit
else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.softeer.podoarrival.unit.quiz;

import com.softeer.podoarrival.event.exception.DailyQuizNotExistsException;
import com.softeer.podoarrival.unit.base.QuizServiceBase;
import com.softeer.podoarrival.event.model.dto.GetQuizResponseDto;
import com.softeer.podoarrival.event.model.entity.Quiz;
Expand Down Expand Up @@ -85,7 +86,7 @@ public void getQuizListFail_CacheMiss() {

// when-then
assertThatThrownBy(() -> quizService.getQuizInfo())
.isInstanceOf(NullPointerException.class);
.isInstanceOf(DailyQuizNotExistsException.class);
}

}

0 comments on commit 07a3e3f

Please sign in to comment.