diff --git a/src/main/java/com/example/demo/base/code/status/exception/ErrorStatus.java b/src/main/java/com/example/demo/base/code/status/exception/ErrorStatus.java index 3d9f461..d42c181 100644 --- a/src/main/java/com/example/demo/base/code/status/exception/ErrorStatus.java +++ b/src/main/java/com/example/demo/base/code/status/exception/ErrorStatus.java @@ -38,7 +38,10 @@ public enum ErrorStatus implements BaseErrorCode { QUESTION_NOT_FOUND(HttpStatus.NOT_FOUND, "QUESTION4005", "해당 질문을 찾을 수 없습니다."), // 답변 관련 에러 - ANSWER_NOT_FOUND(HttpStatus.NOT_FOUND, "ANSWER4004", "해당 답변을 찾을 수 없습니다."); + ANSWER_NOT_FOUND(HttpStatus.NOT_FOUND, "ANSWER4004", "해당 답변을 찾을 수 없습니다."), + + // 답변 & 질문 에러 + QUESTION_ANSWER_NOT_FOUND(HttpStatus.NOT_FOUND, "QUESTION_ANSWER4001", "해당 질문과 답변을 찾을 수 없습니다."); private final HttpStatus httpStatus; diff --git a/src/main/java/com/example/demo/service/answer/AnswerService.java b/src/main/java/com/example/demo/service/answer/AnswerService.java index 3920a7c..055ca5b 100644 --- a/src/main/java/com/example/demo/service/answer/AnswerService.java +++ b/src/main/java/com/example/demo/service/answer/AnswerService.java @@ -48,6 +48,9 @@ public AnswerCreateResponseDto createAnswer(AnswerRequestDto dto) { @Transactional(readOnly = true) public AnswerResponseDto getAnswer(String uuid) { QuestionAnswer questionAnswer = questionAnswerQuery.findByUUID(uuid); + if (questionAnswer == null) { + throw new GeneralException(ErrorStatus.QUESTION_ANSWER_NOT_FOUND.getReasonHttpStatus()); + } return new AnswerResponseDto(questionAnswer.getQuestion().getQuestion(), questionAnswer.getAnswer().getAnswer());