diff --git a/src/main/java/com/developer/wiki/common/ExceptionAdvice.java b/src/main/java/com/developer/wiki/common/ExceptionAdvice.java index ede2c61..daf670d 100644 --- a/src/main/java/com/developer/wiki/common/ExceptionAdvice.java +++ b/src/main/java/com/developer/wiki/common/ExceptionAdvice.java @@ -38,13 +38,6 @@ public ErrorResponse handleConflictException(ConflictException e) { return new ErrorResponse(List.of(e.getMessage())); } - @ResponseBody - @ResponseStatus(HttpStatus.UNAUTHORIZED) - @ExceptionHandler(UnAuthorizedException.class) - public ErrorResponse unAuthorizedException(UnAuthorizedException e) { - return new ErrorResponse(List.of(e.getMessage())); - } - @ResponseBody @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(value = {BindException.class}) @@ -62,7 +55,7 @@ public ErrorResponse missingServletRequestParameterException(ServletRequestBindi } @ResponseBody - @ResponseStatus(HttpStatus.FORBIDDEN) + @ResponseStatus(HttpStatus.UNAUTHORIZED) @ExceptionHandler(UnAuthorizedException.class) public ErrorResponse handleNotMatchPasswordException(UnAuthorizedException e) { return new ErrorResponse(List.of(e.getMessage())); diff --git a/src/main/java/com/developer/wiki/question/command/application/comment/CommentPasswordCheckService.java b/src/main/java/com/developer/wiki/question/command/application/comment/CommentPasswordCheckService.java index b02a1c7..6dcfe33 100644 --- a/src/main/java/com/developer/wiki/question/command/application/comment/CommentPasswordCheckService.java +++ b/src/main/java/com/developer/wiki/question/command/application/comment/CommentPasswordCheckService.java @@ -1,5 +1,6 @@ package com.developer.wiki.question.command.application.comment; +import com.developer.wiki.common.exception.UnAuthorizedException; import com.developer.wiki.question.command.application.dto.PasswordRequest; import com.developer.wiki.question.command.domain.Comment; import com.developer.wiki.question.command.domain.CommentRepository; @@ -18,8 +19,10 @@ public class CommentPasswordCheckService { public boolean checkPassword(Long id, PasswordRequest passwordRequest, Long userId) { Comment comment = commentRepository.findById(id).orElseThrow(EntityNotFoundException::new); - if (Objects.isNull(userId) || userId.equals(comment.getUserId())) { - return comment.checkPassword(passwordRequest.getPassword()); + //Null이 아니면서, id도 맞지 않을때 + if (!Objects.isNull(userId) && !userId.equals(comment.getUserId())) { + throw new UnAuthorizedException("수정 권한이 없습니다."); } + return comment.checkPassword(passwordRequest.getPassword()); } }