/** * 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); }
/** * 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); }
/** * 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); }