List of usage examples for org.springframework.dao DuplicateKeyException getRootCause
@Nullable
public Throwable getRootCause()
From source file:org.exoplatform.acceptance.rest.JsonErrorHandler.java
/** * Catch DuplicateKeyException when an entity creation or update doesn't a constraint of uniqueness in the mongo repository. * * @param ex The exception trapped//from w ww . j av a2 s . co m * @return A standardized {@link org.exoplatform.acceptance.rest.JsonErrorResponse} * @throws java.io.IOException if any. */ @ExceptionHandler(DuplicateKeyException.class) @RequestMapping(produces = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CONFLICT) @ResponseBody public JsonErrorResponse handleDuplicateKeyException(DuplicateKeyException ex) throws IOException { LOGGER.warn("Duplicated Key : {}", ex.getRootCause().getMessage()); return new JsonErrorResponse("Duplicated Key Error", JsonPath.read(ex.getRootCause().getMessage(), "$.err").toString()); }