Skip to content

Commit

Permalink
feat: 회원 관련 Exception Handler 추가 #8
Browse files Browse the repository at this point in the history
  • Loading branch information
PgmJun committed Jan 23, 2024
1 parent 9786be0 commit 9e84964
Showing 1 changed file with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import com.nice.petudio.common.exception.error.ErrorCode;
import com.nice.petudio.common.exception.model.BadGatewayException;
import com.nice.petudio.common.exception.model.ConflictException;
import com.nice.petudio.common.exception.model.ForbiddenException;
import com.nice.petudio.common.exception.model.InternalServerException;
import com.nice.petudio.common.exception.model.NotFoundException;
import com.nice.petudio.common.exception.model.UnAuthorizedException;
import com.nice.petudio.common.exception.model.ValidationException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -69,6 +72,31 @@ protected ApiResponse<Object> handleInvalidFormatException(final Exception excep
return ApiResponse.error(ErrorCode.BAD_REQUEST_EXCEPTION);
}

/**
* 401 UnAuthorized
*/
// 회원 인증에 실패했을 경우 발생
@ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(UnAuthorizedException.class)
protected ApiResponse<Object> handleUnAuthorizedException(
UnAuthorizedException exception) {
log.error(exception.getMessage(), exception);
return ApiResponse.error(exception.getErrorCode());
}

/**
* 403 Forbidden
*/
// 요청에 대한 권한이 존재하지 않는 경우 발생
@ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(ForbiddenException.class)
protected ApiResponse<Object> handleForbiddenException(
ForbiddenException exception) {
log.error(exception.getMessage(), exception);
return ApiResponse.error(exception.getErrorCode());
}


/**
* 404 Not Found
*/
Expand All @@ -78,7 +106,16 @@ protected ApiResponse<Object> handleInvalidFormatException(final Exception excep
protected ApiResponse<Object> handleNoResourceFoundException(
NoResourceFoundException exception) {
log.error(exception.getMessage(), exception);
return ApiResponse.error(ErrorCode.NO_RESOURCE_FOUND_EXCEPTION);
return ApiResponse.error(ErrorCode.NOT_FOUND_EXCEPTION);
}

// 존재하지 않는 정보 요청 시 발생
@ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(NotFoundException.class)
protected ApiResponse<Object> handleNotFoundException(
NotFoundException exception) {
log.error(exception.getMessage(), exception);
return ApiResponse.error(exception.getErrorCode());
}


Expand Down

0 comments on commit 9e84964

Please sign in to comment.