Example usage for org.apache.cassandra.exceptions TransportException getMessage

List of usage examples for org.apache.cassandra.exceptions TransportException getMessage

Introduction

In this page you can find the example usage for org.apache.cassandra.exceptions TransportException getMessage.

Prototype

public String getMessage();

Source Link

Document

The exception message.

Usage

From source file:com.datastax.driver.core.DefaultResultSetFuture.java

License:Apache License

static Exception convertException(org.apache.cassandra.exceptions.TransportException te) {
    switch (te.code()) {
    case SERVER_ERROR:
        return new DriverInternalError("An unexpected error occured server side: " + te.getMessage());
    case PROTOCOL_ERROR:
        return new DriverInternalError(
                "An unexpected protocol error occured. This is a bug in this library, please report: "
                        + te.getMessage());
    case UNAVAILABLE:
        org.apache.cassandra.exceptions.UnavailableException ue = (org.apache.cassandra.exceptions.UnavailableException) te;
        return new UnavailableException(ConsistencyLevel.from(ue.consistency), ue.required, ue.alive);
    case OVERLOADED:
        return new DriverInternalError(
                "Queried host was overloaded; this shouldn't happen, another node should have been tried");
    case IS_BOOTSTRAPPING:
        return new DriverInternalError(
                "Queried host was boostrapping; this shouldn't happen, another node should have been tried");
    case TRUNCATE_ERROR:
        return new TruncateException(te.getMessage());
    case WRITE_TIMEOUT:
        org.apache.cassandra.exceptions.WriteTimeoutException wte = (org.apache.cassandra.exceptions.WriteTimeoutException) te;
        return new WriteTimeoutException(ConsistencyLevel.from(wte.consistency), WriteType.from(wte.writeType),
                wte.received, wte.blockFor);
    case READ_TIMEOUT:
        org.apache.cassandra.exceptions.ReadTimeoutException rte = (org.apache.cassandra.exceptions.ReadTimeoutException) te;
        return new ReadTimeoutException(ConsistencyLevel.from(rte.consistency), rte.received, rte.blockFor,
                rte.dataPresent);// ww  w  . j av a2s.c  o m
    case SYNTAX_ERROR:
        return new SyntaxError(te.getMessage());
    case UNAUTHORIZED:
        return new UnauthorizedException(te.getMessage());
    case INVALID:
        return new InvalidQueryException(te.getMessage());
    case CONFIG_ERROR:
        return new InvalidConfigurationInQueryException(te.getMessage());
    case ALREADY_EXISTS:
        org.apache.cassandra.exceptions.AlreadyExistsException aee = (org.apache.cassandra.exceptions.AlreadyExistsException) te;
        return new AlreadyExistsException(aee.ksName, aee.cfName);
    default:
        return new DriverInternalError("Unknown error return code: " + te.code());
    }
}