Skip to content

Commit

Permalink
Merge pull request #92 from Developer-Wikis/feature/#88
Browse files Browse the repository at this point in the history
fix: 예외 처리 에러를 수정하라.
  • Loading branch information
dhkstnaos authored Nov 17, 2022
2 parents 61c896a + a2e12f1 commit 5db4c11
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
9 changes: 1 addition & 8 deletions src/main/java/com/developer/wiki/common/ExceptionAdvice.java
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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());
}
}

0 comments on commit 5db4c11

Please sign in to comment.