RED-5504 - Prevent using exact same database schema/buckets/index for multiple tenants

- extract the name of the unique constraint
This commit is contained in:
devplant 2023-04-07 16:22:07 +03:00
parent be0978a299
commit d92409dadb

View File

@ -25,6 +25,7 @@ import lombok.extern.slf4j.Slf4j;
@RestControllerAdvice
public class InternalControllerAdvice {
public final String VIOLATES_UNIQUE_CONSTRAINT = "violates unique constraint";
/* error handling */
@ -87,10 +88,11 @@ public class InternalControllerAdvice {
@ExceptionHandler(value = SQLException.class)
public ResponseEntity<ErrorMessage> handleSQLException(SQLException e) {
if (e.getMessage().contains("violates unique constraint")) {
int index = e.getMessage().indexOf("violates unique constraint");
String violation_key = e.getMessage().substring(index);
return new ResponseEntity<>(new ErrorMessage(OffsetDateTime.now(), "Unique constraint violation" + violation_key), HttpStatus.CONFLICT);
if (e.getMessage().contains(VIOLATES_UNIQUE_CONSTRAINT)) {
int indexFrom = e.getMessage().indexOf(VIOLATES_UNIQUE_CONSTRAINT) + VIOLATES_UNIQUE_CONSTRAINT.length();
int indexTo = e.getMessage().indexOf("Detail");
String violation_key = e.getMessage().substring(indexFrom, indexTo);
return new ResponseEntity<>(new ErrorMessage(OffsetDateTime.now(), "Unique constraint violation: " + violation_key), HttpStatus.CONFLICT);
} else if (e.getMessage().contains("No suitable driver found")) {
return new ResponseEntity<>(new ErrorMessage(OffsetDateTime.now(), "JDBC URL is incorrect"), HttpStatus.BAD_REQUEST);
} else {