Search in sources :

Example 1 with NoSuchConnectionException

use of org.apache.calcite.avatica.NoSuchConnectionException in project calcite-avatica by apache.

the class AbstractHandler method unwrapException.

/**
   * Unwrap Avatica-specific context about a given exception.
   *
   * @param e A caught exception throw by Avatica implementation.
   * @return An {@link ErrorResponse}.
   */
ErrorResponse unwrapException(Exception e) {
    // By default, we know nothing extra.
    int errorCode = ErrorResponse.UNKNOWN_ERROR_CODE;
    String sqlState = ErrorResponse.UNKNOWN_SQL_STATE;
    AvaticaSeverity severity = AvaticaSeverity.UNKNOWN;
    String errorMsg = null;
    // Extract the contextual information if we have it. We may not.
    if (e instanceof AvaticaRuntimeException) {
        AvaticaRuntimeException rte = (AvaticaRuntimeException) e;
        errorCode = rte.getErrorCode();
        sqlState = rte.getSqlState();
        severity = rte.getSeverity();
        errorMsg = rte.getErrorMessage();
    } else if (e instanceof NoSuchConnectionException) {
        errorCode = ErrorResponse.MISSING_CONNECTION_ERROR_CODE;
        severity = AvaticaSeverity.ERROR;
        errorMsg = e.getMessage();
    } else {
        // Try to construct a meaningful error message when the server impl doesn't provide one.
        errorMsg = getCausalChain(e);
    }
    return new ErrorResponse(e, errorMsg, errorCode, sqlState, severity, metadata);
}
Also used : AvaticaSeverity(org.apache.calcite.avatica.AvaticaSeverity) NoSuchConnectionException(org.apache.calcite.avatica.NoSuchConnectionException) ErrorResponse(org.apache.calcite.avatica.remote.Service.ErrorResponse)

Aggregations

AvaticaSeverity (org.apache.calcite.avatica.AvaticaSeverity)1 NoSuchConnectionException (org.apache.calcite.avatica.NoSuchConnectionException)1 ErrorResponse (org.apache.calcite.avatica.remote.Service.ErrorResponse)1