Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] quiz exception 및 에러 logger 추가 #24

Merged
merged 4 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기 에러가 실제로 뜨나요? Logger 문법이 이렇게도 되는지 궁금합니다

Copy link
Collaborator

@eckrin eckrin Aug 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image 신기방기하네요

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);
}

}
Loading