|
|
@ -6,11 +6,14 @@ import com.xit.core.exception.CustomBaseException;
|
|
|
|
import com.xit.core.util.Checks;
|
|
|
|
import com.xit.core.util.Checks;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
|
|
import org.hibernate.JDBCException;
|
|
|
|
|
|
|
|
import org.hibernate.exception.GenericJDBCException;
|
|
|
|
import org.springframework.dao.DataIntegrityViolationException;
|
|
|
|
import org.springframework.dao.DataIntegrityViolationException;
|
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
import org.springframework.http.converter.HttpMessageNotReadableException;
|
|
|
|
import org.springframework.http.converter.HttpMessageNotReadableException;
|
|
|
|
|
|
|
|
import org.springframework.orm.jpa.JpaSystemException;
|
|
|
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
|
|
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
|
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
|
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
|
|
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
|
|
@ -18,6 +21,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
|
|
import org.springframework.web.context.request.WebRequest;
|
|
|
|
import org.springframework.web.context.request.WebRequest;
|
|
|
|
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
|
|
|
|
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.persistence.PersistenceException;
|
|
|
|
import javax.validation.ConstraintViolationException;
|
|
|
|
import javax.validation.ConstraintViolationException;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
@ -189,6 +193,12 @@ public class CustomRestExceptionHandler extends ResponseEntityExceptionHandler {
|
|
|
|
protected ResponseEntity<RestErrorResponse> handleRuntimeException(RuntimeException e) {
|
|
|
|
protected ResponseEntity<RestErrorResponse> handleRuntimeException(RuntimeException e) {
|
|
|
|
String message = Checks.isNotNull(e) ? e.getLocalizedMessage() : StringUtils.EMPTY;
|
|
|
|
String message = Checks.isNotNull(e) ? e.getLocalizedMessage() : StringUtils.EMPTY;
|
|
|
|
log.error("handleException RuntimeException : {}", Checks.isEmpty(message) ? StringUtils.EMPTY : e.getClass().getCanonicalName());
|
|
|
|
log.error("handleException RuntimeException : {}", Checks.isEmpty(message) ? StringUtils.EMPTY : e.getClass().getCanonicalName());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Hibernate SQL 예외인 경우 메세지 획득
|
|
|
|
|
|
|
|
if(e instanceof PersistenceException || e instanceof JDBCException || e instanceof JpaSystemException || e instanceof GenericJDBCException){
|
|
|
|
|
|
|
|
message = ((GenericJDBCException) e.getCause()).getSQLException().getLocalizedMessage();
|
|
|
|
|
|
|
|
//message = ((GenericJDBCException) e.getCause()).getSQLException().getLocalizedMessage();
|
|
|
|
|
|
|
|
}
|
|
|
|
return RestErrorResponse.of(HttpStatus.INTERNAL_SERVER_ERROR.toString(), message);
|
|
|
|
return RestErrorResponse.of(HttpStatus.INTERNAL_SERVER_ERROR.toString(), message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|