=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/CrudControllerAdvice.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/CrudControllerAdvice.java 2016-01-14 12:59:29 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/CrudControllerAdvice.java 2016-01-25 09:20:30 +0000 @@ -34,8 +34,8 @@ import org.hisp.dhis.common.MaintenanceModeException; import org.hisp.dhis.common.exception.InvalidIdentifierReferenceException; import org.hisp.dhis.dataapproval.exceptions.DataApprovalException; +import org.hisp.dhis.dxf2.common.Status; import org.hisp.dhis.dxf2.webmessage.WebMessageException; -import org.hisp.dhis.dxf2.common.Status; import org.hisp.dhis.query.QueryException; import org.hisp.dhis.query.QueryParserException; import org.hisp.dhis.system.util.DateUtils; @@ -45,6 +45,7 @@ import org.hisp.dhis.webapi.utils.WebMessageUtils; import org.jasypt.exceptions.EncryptionOperationNotPossibleException; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DataIntegrityViolationException; import org.springframework.security.access.AccessDeniedException; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.annotation.ControllerAdvice; @@ -151,4 +152,11 @@ { webMessageService.send( WebMessageUtils.createWebMessage( ex.getMessage(), Status.ERROR, ex.getStatusCode() ), response, request ); } + + @ExceptionHandler( DataIntegrityViolationException.class ) + public void dataIntegrityViolationExceptionHandler( DataIntegrityViolationException ex, HttpServletResponse response, HttpServletRequest request ) + { + webMessageService.send( WebMessageUtils.conflict( ex.getMessage() ), response, request ); + throw ex; + } }