Pull request #666: RED-5504 - Prevent using exact same database schema/buckets/index for multiple tenants

Merge in RED/persistence-service from RED-5504-message to master

* commit 'd92409dadbeb8a48a377d079a5d49ac6d0476d43':
  RED-5504 - Prevent using exact same database schema/buckets/index for multiple tenants - extract the name of the unique constraint
  RED-5504 - Prevent using exact same database schema/buckets/index for multiple tenants - update the sql messages
This commit is contained in:
Corina Olariu 2023-04-10 10:32:42 +02:00 committed by Timo Bejan
commit 796cc3c8cc

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,13 +88,16 @@ public class InternalControllerAdvice {
@ExceptionHandler(value = SQLException.class)
public ResponseEntity<ErrorMessage> handleSQLException(SQLException e) {
if (e.getMessage().contains("violates unique constraint")) {
return new ResponseEntity<>(new ErrorMessage(OffsetDateTime.now(), "Unique constraint violation"), 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 {
log.error("PLSQL Exception occurred: {}", e.getMessage(), e);
return new ResponseEntity<>(new ErrorMessage(OffsetDateTime.now(), "SQL Exception"), HttpStatus.INTERNAL_SERVER_ERROR);
return new ResponseEntity<>(new ErrorMessage(OffsetDateTime.now(), "SQL Exception" + e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
}
}