Skip to content

Commit 4ea816c

Browse files
committed
code improvements
1 parent 2148f8c commit 4ea816c

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/main/java/it/gov/pagopa/node/cfg_sync/exception/ErrorHandler.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,9 @@ public ResponseEntity<ProblemJson> handleDataIntegrityViolationException(
152152
final DataIntegrityViolationException ex, final WebRequest request) {
153153
ProblemJson errorResponse = null;
154154

155-
if (ex.getCause() instanceof ConstraintViolationException) {
156-
String sqlState = ((ConstraintViolationException) ex.getCause()).getSQLState();
157-
var errorCode = ((ConstraintViolationException) ex.getCause()).getSQLException()
158-
.getErrorCode();
155+
if (ex.getCause() instanceof ConstraintViolationException constraintViolationException) {
156+
String sqlState = constraintViolationException.getSQLState();
157+
var errorCode = constraintViolationException.getSQLException().getErrorCode();
159158
// check the reason of ConstraintViolationException: is true if the object is referenced by a foreign key
160159
// more info: https://docs.oracle.com/javadb/10.8.3.0/ref/rrefexcept71493.html
161160
if (sqlState.equals(FOREIGN_KEY_VIOLATION)) {

0 commit comments

Comments
 (0)