class DbRequestHelper {

    public static boolean isDuplicateKeyError(Exception e) {
        if (e instanceof MongoBulkWriteException || e instanceof MongoWriteException) {
            return isDuplicateKeyException(e);
        }

        if (e instanceof DatabaseException &&
            (e.getCause() instanceof MongoBulkWriteException || e.getCause() instanceof MongoWriteException)) {
            return isDuplicateKeyException(e.getCause());
        }
        Throwable d = e.getCause();
        if (d instanceof DatabaseException &&
            (d.getCause() instanceof MongoBulkWriteException || d.getCause() instanceof MongoWriteException)) {
            return isDuplicateKeyException(e.getCause());
        }
        return false;
    }

    private  DbRequestHelper();

}