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 68424d5 commit e62d6f2
Showing 1 changed file with 50 additions and 0 deletions.
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 All @@ -18,6 +21,7 @@
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import org.springframework.web.servlet.resource.NoResourceFoundException;

@Slf4j
@RestControllerAdvice
Expand Down Expand Up @@ -68,6 +72,52 @@ 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
*/
// 존재하지 않는 API 주소로 요청 시 발생
@ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(NoResourceFoundException.class)
protected ApiResponse<Object> handleNoResourceFoundException(
NoResourceFoundException exception) {
log.error(exception.getMessage(), 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());
}


/**
* 405 Method Not Supported
Expand Down

0 comments on commit e62d6f2

Please sign in to comment.