Example usage for org.springframework.dao DuplicateKeyException getRootCause

List of usage examples for org.springframework.dao DuplicateKeyException getRootCause

Introduction

In this page you can find the example usage for org.springframework.dao DuplicateKeyException getRootCause.

Prototype

@Nullable
public Throwable getRootCause() 

Source Link

Document

Retrieve the innermost cause of this exception, if any.

Usage

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());
}