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

GlobalExceptionHandler에 누락된 커스텀 예외 처리 추가 #252

Merged
merged 2 commits into from
Nov 9, 2023
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 @@ -11,9 +11,13 @@
import com.daggle.animory.domain.pet.exception.InvalidPetMonthRangeException;
import com.daggle.animory.domain.pet.exception.InvalidPetYearRangeException;
import com.daggle.animory.domain.pet.exception.PetNotFoundException;
import com.daggle.animory.domain.pet.exception.PetPermissionDeniedException;
import com.daggle.animory.domain.shelter.exception.ShelterAlreadyExistException;
import com.daggle.animory.domain.shelter.exception.ShelterNotFoundException;
import com.daggle.animory.domain.shelter.exception.ShelterPermissionDeniedException;
import com.daggle.animory.domain.shortform.exception.AlreadyLikedPetVideoException;
import com.daggle.animory.domain.shortform.exception.NotLikedPetVideoException;
import com.daggle.animory.domain.shortform.exception.ShortFormNotFoundException;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -108,6 +112,18 @@ public ResponseEntity<Response<Void>> handleShelterAlreadyExistException(final E
HttpStatus.BAD_REQUEST));
}

@ExceptionHandler({AlreadyLikedPetVideoException.class})
public ResponseEntity<Response<Void>> handleAlreadyLikedPetVideoException(final Exception e) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(Response.error(e.getMessage(),
HttpStatus.BAD_REQUEST));
}

@ExceptionHandler({NotLikedPetVideoException.class})
public ResponseEntity<Response<Void>> handleNotLikedPetVideoException(final Exception e) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(Response.error(e.getMessage(),
HttpStatus.BAD_REQUEST));
}

// 401
@ExceptionHandler({UnAuthorizedException.class})
public ResponseEntity<Response<Void>> handleUnAuthorizedException(final Exception e) {
Expand All @@ -122,6 +138,11 @@ public ResponseEntity<Response<Void>> handleShelterPermissionDeniedException(fin
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(Response.error(e.getMessage(), HttpStatus.FORBIDDEN));
}

@ExceptionHandler({PetPermissionDeniedException.class})
public ResponseEntity<Response<Void>> handlePetPermissionDeniedException(final Exception e) {
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(Response.error(e.getMessage(), HttpStatus.FORBIDDEN));
}

@ExceptionHandler({ForbiddenException.class})
public ResponseEntity<Response<Void>> handleForbiddenExceptionn(final Exception e) {
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(Response.error(e.getMessage(), HttpStatus.FORBIDDEN));
Expand All @@ -137,6 +158,10 @@ public ResponseEntity<Response<Void>> handlePetNotFoundException(final Exception
public ResponseEntity<Response<Void>> handleShelterNotFoundException(final Exception e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(Response.error(e.getMessage(), HttpStatus.NOT_FOUND));
}
@ExceptionHandler({ShortFormNotFoundException.class})
public ResponseEntity<Response<Void>> handleShortFormNotFoundException(final Exception e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(Response.error(e.getMessage(), HttpStatus.NOT_FOUND));
}

@ExceptionHandler({MaxUploadSizeExceededException.class})
public ResponseEntity<Response<Void>> handleMaxUploadSizeExceededException(final RuntimeException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.daggle.animory.domain.shortform.exception;

public class AlreadyLikedPetVideo extends RuntimeException {
public class AlreadyLikedPetVideoException extends RuntimeException {
@Override
public String getMessage() {
return ShortFormExceptionMessage.ALREADY_LIKED_PET_VIDEO.getMessage();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.daggle.animory.domain.shortform.exception;

public class NotLikedPetVideo extends RuntimeException {
public class NotLikedPetVideoException extends RuntimeException {
@Override
public String getMessage() {
return ShortFormExceptionMessage.NOT_LIKED_PET_VIDEO.getMessage();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.daggle.animory.domain.shortform.exception;

public class ShortFormNotFound extends RuntimeException {
public class ShortFormNotFoundException extends RuntimeException {
@Override
public String getMessage() {
return ShortFormExceptionMessage.SHORT_FORM_NOT_FOUND.getMessage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import com.daggle.animory.domain.pet.entity.PetVideo;
import com.daggle.animory.domain.shortform.entity.PetVideoLike;
import com.daggle.animory.domain.shortform.exception.AlreadyLikedPetVideo;
import com.daggle.animory.domain.shortform.exception.NotLikedPetVideo;
import com.daggle.animory.domain.shortform.exception.ShortFormNotFound;
import com.daggle.animory.domain.shortform.exception.AlreadyLikedPetVideoException;
import com.daggle.animory.domain.shortform.exception.NotLikedPetVideoException;
import com.daggle.animory.domain.shortform.exception.ShortFormNotFoundException;
import com.daggle.animory.domain.shortform.repository.PetVideoJpaRepository;
import com.daggle.animory.domain.shortform.repository.PetVideoLikeRepository;
import lombok.RequiredArgsConstructor;
Expand All @@ -22,7 +22,7 @@ public void updatePetVideoLikeCount(final String IPAddress, final int petVideoId
validatePetVideoLikeDuplication(IPAddress, petVideoId);

final PetVideo petVideo = petVideoJpaRepository.findById(petVideoId)
.orElseThrow(ShortFormNotFound::new);
.orElseThrow(ShortFormNotFoundException::new);

petVideo.updateLikeCount();

Expand All @@ -36,7 +36,7 @@ public void deletePetVideoLikeCount(final String ipAddress, final int petVideoId
validatePetVideoLikeDelete(ipAddress, petVideoId);

final PetVideo petVideo = petVideoJpaRepository.findById(petVideoId)
.orElseThrow(ShortFormNotFound::new);
.orElseThrow(ShortFormNotFoundException::new);

petVideo.deleteLikeCount();

Expand All @@ -45,13 +45,13 @@ public void deletePetVideoLikeCount(final String ipAddress, final int petVideoId

private void validatePetVideoLikeDuplication(final String IPAddress, final int petVideoId) {
if (petVideoLikeRepository.existsByIpAddressAndPetVideoId(IPAddress, petVideoId)) {
throw new AlreadyLikedPetVideo();
throw new AlreadyLikedPetVideoException();
}
}

private void validatePetVideoLikeDelete(final String IPAddress, final int petVideoId) {
if (!petVideoLikeRepository.existsByIpAddressAndPetVideoId(IPAddress, petVideoId)) {
throw new NotLikedPetVideo();
throw new NotLikedPetVideoException();
}
}
}