Skip to content

Commit

Permalink
[SHIBUI-996]
Browse files Browse the repository at this point in the history
Added exception handler for database constraint exception.
Added i18n error message.
  • Loading branch information
Bill Smith committed Nov 29, 2018
1 parent a568b32 commit 98d18c0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package edu.internet2.tier.shibboleth.admin.ui.controller.support;

import com.google.common.collect.ImmutableMap;
import edu.internet2.tier.shibboleth.admin.ui.controller.ErrorResponse;
import edu.internet2.tier.shibboleth.admin.ui.domain.resolvers.MetadataResolver;
import edu.internet2.tier.shibboleth.admin.ui.repository.MetadataResolverRepository;
import org.hibernate.exception.ConstraintViolationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.client.HttpClientErrorException;

import static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.springframework.http.HttpStatus.NOT_FOUND;

/**
Expand Down Expand Up @@ -38,4 +41,9 @@ public ResponseEntity<?> notFoundHandler(HttpClientErrorException ex) {
}
throw ex;
}

@ExceptionHandler(ConstraintViolationException.class)
public ResponseEntity<ErrorResponse> handleDatabaseConstraintViolation(ConstraintViolationException ex) {
return ResponseEntity.status(BAD_REQUEST).body(new ErrorResponse("400", "message.database-constraint"));
}
}
1 change: 1 addition & 0 deletions backend/src/main/resources/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ message.wizard-status=Step { index } of { length }
message.entity-id-min-unique=You must add at least one entity id target and they must each be unique.
message.required-for-scripts=Required for Scripts
message.required-for-regex=Required for Regex
message.database-constraint=There was a database constraint problem processing the request. Check the request to insure that fields that must be unique are truly unique.

tooltip.entity-id=Entity ID
tooltip.service-provider-name=Service Provider Name (Dashboard Display Only)
Expand Down
1 change: 1 addition & 0 deletions backend/src/main/resources/i18n/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ message.wizard-status=Step { index } of { length }
message.entity-id-min-unique=You must add at least one entity id target and they must each be unique.
message.required-for-scripts=Required for Scripts
message.required-for-regex=Required for Regex
message.database-constraint=There was a database constraint problem processing the request. Check the request to insure that fields that must be unique are truly unique.

tooltip.entity-id=Entity ID
tooltip.service-provider-name=Service Provider Name (Dashboard Display Only)
Expand Down

0 comments on commit 98d18c0

Please sign in to comment.