private static ExceptionData makeExceptionData(IOException exception, boolean idempotent) { int code = UNKNOWN_CODE; Boolean retryable = null; if (exception instanceof HttpResponseException) { // In cases where an exception is an instance of HttpResponseException, // check the status code to determine whether it's retryable code = ((HttpResponseException) exception).getStatusCode(); retryable = BaseServiceException.isRetryable(code, null, idempotent, Collections.<Error>emptySet()); } return ExceptionData.newBuilder() .setMessage(exception.getMessage()) .setCause(exception) .setRetryable( MoreObjects.firstNonNull( retryable, BaseServiceException.isRetryable(idempotent, exception))) .setCode(code) .setReason(null) .setLocation(null) .setDebugInfo(null) .build(); }
.setCode(code) .setReason(reason) .setLocation(location) .setDebugInfo(debugInfo) .build();
private static ExceptionData makeExceptionData( GoogleJsonError googleJsonError, boolean idempotent, Set<BaseServiceException.Error> retryableErrors) { int code = googleJsonError.getCode(); String reason = reason(googleJsonError); ExceptionData.Builder exceptionData = ExceptionData.newBuilder(); exceptionData .setMessage(googleJsonError.getMessage()) .setCause(null) .setRetryable(BaseServiceException.isRetryable(code, reason, idempotent, retryableErrors)) .setCode(code) .setReason(reason); if (reason != null) { GoogleJsonError.ErrorInfo errorInfo = googleJsonError.getErrors().get(0); exceptionData.setLocation(errorInfo.getLocation()); exceptionData.setDebugInfo((String) errorInfo.get("debugInfo")); } else { exceptionData.setLocation(null); exceptionData.setDebugInfo(null); } return exceptionData.build(); }
.setCode(code) .setReason(reason) .setLocation(location) .setDebugInfo(debugInfo) .build();
private static ExceptionData makeExceptionData(IOException exception, boolean idempotent) { int code = UNKNOWN_CODE; Boolean retryable = null; if (exception instanceof HttpResponseException) { // In cases where an exception is an instance of HttpResponseException, // check the status code to determine whether it's retryable code = ((HttpResponseException) exception).getStatusCode(); retryable = BaseServiceException.isRetryable(code, null, idempotent, Collections.<Error>emptySet()); } return ExceptionData.newBuilder() .setMessage(exception.getMessage()) .setCause(exception) .setRetryable( MoreObjects.firstNonNull( retryable, BaseServiceException.isRetryable(idempotent, exception))) .setCode(code) .setReason(null) .setLocation(null) .setDebugInfo(null) .build(); }
private static ExceptionData makeExceptionData( GoogleJsonError googleJsonError, boolean idempotent, Set<BaseServiceException.Error> retryableErrors) { int code = googleJsonError.getCode(); String reason = reason(googleJsonError); ExceptionData.Builder exceptionData = ExceptionData.newBuilder(); exceptionData .setMessage(googleJsonError.getMessage()) .setCause(null) .setRetryable(BaseServiceException.isRetryable(code, reason, idempotent, retryableErrors)) .setCode(code) .setReason(reason); if (reason != null) { GoogleJsonError.ErrorInfo errorInfo = googleJsonError.getErrors().get(0); exceptionData.setLocation(errorInfo.getLocation()); exceptionData.setDebugInfo((String) errorInfo.get("debugInfo")); } else { exceptionData.setLocation(null); exceptionData.setDebugInfo(null); } return exceptionData.build(); }
@InternalApi("This class should only be extended within google-cloud-java") protected BaseHttpServiceException( int code, String message, String reason, boolean idempotent, Set<BaseServiceException.Error> retryableErrors, Throwable cause) { super( ExceptionData.newBuilder() .setMessage(message) .setCause(cause) .setRetryable( BaseServiceException.isRetryable(code, reason, idempotent, retryableErrors)) .setCode(code) .setReason(reason) .setLocation(null) .setDebugInfo(null) .build()); }
@BetaApi public BaseGrpcServiceException(ApiException apiException) { super( ExceptionData.newBuilder() .setMessage(apiException.getMessage()) .setCause(apiException) .setRetryable(apiException.isRetryable()) .setCode(apiException.getStatusCode().getCode().getHttpStatusCode()) .setReason(apiException.getStatusCode().getCode().name()) .setLocation(null) .setDebugInfo(null) .build()); } }
.setRetryable(RETRYABLE) .setDebugInfo(DEBUG_INFO) .setLocation(LOCATION) .build()); assertEquals(CODE, serviceException.getCode());
@InternalApi("This class should only be extended within google-cloud-java") protected BaseHttpServiceException( int code, String message, String reason, boolean idempotent, Set<BaseServiceException.Error> retryableErrors, Throwable cause) { super( ExceptionData.newBuilder() .setMessage(message) .setCause(cause) .setRetryable( BaseServiceException.isRetryable(code, reason, idempotent, retryableErrors)) .setCode(code) .setReason(reason) .setLocation(null) .setDebugInfo(null) .build()); }
@BetaApi public BaseGrpcServiceException(ApiException apiException) { super( ExceptionData.newBuilder() .setMessage(apiException.getMessage()) .setCause(apiException) .setRetryable(apiException.isRetryable()) .setCode(apiException.getStatusCode().getCode().getHttpStatusCode()) .setReason(apiException.getStatusCode().getCode().name()) .setLocation(null) .setDebugInfo(null) .build()); } }