本文整理汇总了Java中com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo类的典型用法代码示例。如果您正苦于以下问题:Java ErrorInfo类的具体用法?Java ErrorInfo怎么用?Java ErrorInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ErrorInfo类属于com.google.api.client.googleapis.json.GoogleJsonError包,在下文中一共展示了ErrorInfo类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: create_adminApiNotEnabled
import com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo; //导入依赖的package包/类
@Test
public void create_adminApiNotEnabled() throws IOException {
ErrorInfo error = new ErrorInfo();
error.setReason(SslSocketFactory.ADMIN_API_NOT_ENABLED_REASON);
GoogleJsonError details = new GoogleJsonError();
details.setErrors(ImmutableList.of(error));
when(adminApiInstancesGet.execute())
.thenThrow(
new GoogleJsonResponseException(
new HttpResponseException.Builder(403, "Forbidden", new HttpHeaders()),
details));
SslSocketFactory sslSocketFactory =
new SslSocketFactory(new Clock(), clientKeyPair, credential, adminApi, 3307);
try {
sslSocketFactory.create(INSTANCE_CONNECTION_STRING);
fail("Expected RuntimeException");
} catch (RuntimeException e) {
// TODO(berezv): should we throw something more specific than RuntimeException?
assertThat(e.getMessage()).contains("Cloud SQL API is not enabled");
}
}
开发者ID:GoogleCloudPlatform,项目名称:cloud-sql-jdbc-socket-factory,代码行数:23,代码来源:SslSocketFactoryTest.java
示例2: create_notAuthorizedToGetInstance
import com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo; //导入依赖的package包/类
@Test
public void create_notAuthorizedToGetInstance() throws IOException {
ErrorInfo error = new ErrorInfo();
error.setReason(SslSocketFactory.INSTANCE_NOT_AUTHORIZED_REASON);
GoogleJsonError details = new GoogleJsonError();
details.setErrors(ImmutableList.of(error));
when(adminApiInstancesGet.execute())
.thenThrow(
new GoogleJsonResponseException(
new HttpResponseException.Builder(403, "Forbidden", new HttpHeaders()),
details));
SslSocketFactory sslSocketFactory =
new SslSocketFactory(new Clock(), clientKeyPair, credential, adminApi, 3307);
try {
sslSocketFactory.create(INSTANCE_CONNECTION_STRING);
fail("Expected RuntimeException");
} catch (RuntimeException e) {
// TODO(berezv): should we throw something more specific than RuntimeException?
assertThat(e.getMessage()).contains("not authorized");
}
}
开发者ID:GoogleCloudPlatform,项目名称:cloud-sql-jdbc-socket-factory,代码行数:23,代码来源:SslSocketFactoryTest.java
示例3: create_notAuthorizedToCreateEphemeralCertificate
import com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo; //导入依赖的package包/类
@Test
public void create_notAuthorizedToCreateEphemeralCertificate() throws IOException {
ErrorInfo error = new ErrorInfo();
error.setReason(SslSocketFactory.INSTANCE_NOT_AUTHORIZED_REASON);
GoogleJsonError details = new GoogleJsonError();
details.setErrors(ImmutableList.of(error));
when(adminApiSslCertsCreateEphemeral.execute())
.thenThrow(
new GoogleJsonResponseException(
new HttpResponseException.Builder(403, "Forbidden", new HttpHeaders()),
details));
SslSocketFactory sslSocketFactory =
new SslSocketFactory(new Clock(), clientKeyPair, credential, adminApi, 3307);
try {
sslSocketFactory.create(INSTANCE_CONNECTION_STRING);
fail();
} catch (RuntimeException e) {
// TODO(berezv): should we throw something more specific than RuntimeException?
assertThat(e.getMessage()).contains("Unable to obtain ephemeral certificate");
}
}
开发者ID:GoogleCloudPlatform,项目名称:cloud-sql-jdbc-socket-factory,代码行数:23,代码来源:SslSocketFactoryTest.java
示例4: setUp
import com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
accessDenied = googleJsonResponseException(
HttpStatusCodes.STATUS_CODE_FORBIDDEN, "Forbidden", "Forbidden");
statusOk = googleJsonResponseException(
HttpStatusCodes.STATUS_CODE_OK, "A reason", "ok");
notFound = googleJsonResponseException(
HttpStatusCodes.STATUS_CODE_NOT_FOUND, "Not found", "Not found");
badRange = googleJsonResponseException(
ApiErrorExtractor.STATUS_CODE_RANGE_NOT_SATISFIABLE, "Bad range", "Bad range");
alreadyExists = googleJsonResponseException(
409, "409", "409");
resourceNotReady = googleJsonResponseException(
400, ApiErrorExtractor.RESOURCE_NOT_READY_REASON_CODE, "Resource not ready");
// This works because googleJsonResponseException takes final ErrorInfo
ErrorInfo errorInfo = new ErrorInfo();
errorInfo.setReason(ApiErrorExtractor.RATE_LIMITED_REASON_CODE);
notRateLimited = googleJsonResponseException(POSSIBLE_RATE_LIMIT, errorInfo, "");
errorInfo.setDomain(ApiErrorExtractor.USAGE_LIMITS_DOMAIN);
rateLimited = googleJsonResponseException(POSSIBLE_RATE_LIMIT, errorInfo, "");
errorInfo.setDomain(ApiErrorExtractor.GLOBAL_DOMAIN);
bigqueryRateLimited = googleJsonResponseException(POSSIBLE_RATE_LIMIT, errorInfo, "");
}
开发者ID:GoogleCloudPlatform,项目名称:bigdata-interop,代码行数:25,代码来源:ApiErrorExtractorTest.java
示例5: checkGoogleJsonResponseException
import com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo; //导入依赖的package包/类
protected static void checkGoogleJsonResponseException(GoogleJsonResponseException e)
throws GoogleJsonResponseException {
GoogleJsonError err = e.getDetails();
// err can be null if response is not JSON
if (err != null) {
// For errors in the 4xx range, print out the errors and continue normally.
if (err.getCode() >= 400 && err.getCode() < 500) {
System.out.printf("There are %d error(s)%n", err.getErrors().size());
for (ErrorInfo info : err.getErrors()) {
System.out.printf("- [%s] %s%n", info.getReason(), info.getMessage());
}
} else {
throw e;
}
} else {
throw e;
}
}
开发者ID:googleads,项目名称:googleads-shopping-samples,代码行数:19,代码来源:BaseWorkflowSample.java
示例6: googleJsonResponseException
import com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo; //导入依赖的package包/类
/**
* Builds a fake GoogleJsonResponseException for testing API error handling.
*/
private static GoogleJsonResponseException googleJsonResponseException(
final int status, final String reason, final String message) throws IOException {
final JsonFactory jsonFactory = new JacksonFactory();
HttpTransport transport = new MockHttpTransport() {
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
ErrorInfo errorInfo = new ErrorInfo();
errorInfo.setReason(reason);
errorInfo.setMessage(message);
errorInfo.setFactory(jsonFactory);
GenericJson error = new GenericJson();
error.set("code", status);
error.set("errors", Arrays.asList(errorInfo));
error.setFactory(jsonFactory);
GenericJson errorResponse = new GenericJson();
errorResponse.set("error", error);
errorResponse.setFactory(jsonFactory);
return new MockLowLevelHttpRequest().setResponse(
new MockLowLevelHttpResponse().setContent(errorResponse.toPrettyString())
.setContentType(Json.MEDIA_TYPE).setStatusCode(status));
}
};
HttpRequest request =
transport.createRequestFactory().buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL);
request.setThrowExceptionOnExecuteError(false);
HttpResponse response = request.execute();
return GoogleJsonResponseException.from(jsonFactory, response);
}
开发者ID:apache,项目名称:beam,代码行数:32,代码来源:GcsUtilTest.java
示例7: errorWithReasonAndStatus
import com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo; //导入依赖的package包/类
/** A helper that generates the error JSON payload that Google APIs produce. */
private static GoogleJsonErrorContainer errorWithReasonAndStatus(String reason, int status) {
ErrorInfo info = new ErrorInfo();
info.setReason(reason);
info.setDomain("global");
// GoogleJsonError contains one or more ErrorInfo objects; our utiities read the first one.
GoogleJsonError error = new GoogleJsonError();
error.setErrors(ImmutableList.of(info));
error.setCode(status);
error.setMessage(reason);
// The actual JSON response is an error container.
GoogleJsonErrorContainer container = new GoogleJsonErrorContainer();
container.setError(error);
return container;
}
开发者ID:apache,项目名称:beam,代码行数:16,代码来源:BigQueryServicesImplTest.java
示例8: accessDeniedNonRecoverable
import com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo; //导入依赖的package包/类
/**
* Determine if a given GoogleJsonError is caused by, and only by,
* account disabled error.
*/
public boolean accessDeniedNonRecoverable(GoogleJsonError e) {
ErrorInfo errorInfo = getErrorInfo(e);
if (errorInfo != null) {
String reason = errorInfo.getReason();
return ACCOUNT_DISABLED_REASON_CODE.equals(reason)
|| ACCESS_NOT_CONFIGURED_REASON_CODE.equals(reason);
}
return false;
}
开发者ID:GoogleCloudPlatform,项目名称:bigdata-interop,代码行数:14,代码来源:ApiErrorExtractor.java
示例9: fieldSizeTooLarge
import com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo; //导入依赖的package包/类
/**
* Determines if the given GoogleJsonError indicates 'field size too large'.
*/
public boolean fieldSizeTooLarge(GoogleJsonError e) {
ErrorInfo errorInfo = getErrorInfo(e);
if (errorInfo != null) {
String reason = errorInfo.getReason();
return FIELD_SIZE_TOO_LARGE.equals(reason);
}
return false;
}
开发者ID:GoogleCloudPlatform,项目名称:bigdata-interop,代码行数:12,代码来源:ApiErrorExtractor.java
示例10: resourceNotReady
import com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo; //导入依赖的package包/类
/**
* Determines if the given GoogleJsonError indicates 'resource not ready'.
*/
public boolean resourceNotReady(GoogleJsonError e) {
ErrorInfo errorInfo = getErrorInfo(e);
if (errorInfo != null) {
String reason = errorInfo.getReason();
return RESOURCE_NOT_READY_REASON_CODE.equals(reason);
}
return false;
}
开发者ID:GoogleCloudPlatform,项目名称:bigdata-interop,代码行数:12,代码来源:ApiErrorExtractor.java
示例11: rateLimited
import com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo; //导入依赖的package包/类
/**
* Determine if a given GoogleJsonError is caused by, and only by,
* a rate limit being applied.
* @param e The GoogleJsonError returned by the request
* @return True if the error is caused by a rate limit being applied.
*/
public boolean rateLimited(GoogleJsonError e) {
ErrorInfo errorInfo = getErrorInfo(e);
if (errorInfo != null) {
String domain = errorInfo.getDomain();
String reason = errorInfo.getReason();
boolean isRateLimitedOrGlobalDomain =
USAGE_LIMITS_DOMAIN.equals(domain) || GLOBAL_DOMAIN.equals(domain);
boolean isRateLimitedReason =
RATE_LIMITED_REASON_CODE.equals(reason) || USER_RATE_LIMITED_REASON_CODE.equals(reason);
return isRateLimitedOrGlobalDomain && isRateLimitedReason;
}
return false;
}
开发者ID:GoogleCloudPlatform,项目名称:bigdata-interop,代码行数:20,代码来源:ApiErrorExtractor.java
示例12: getErrorInfo
import com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo; //导入依赖的package包/类
/**
* Get the first ErrorInfo from an IOException if it is an instance of
* GoogleJsonResponseException, otherwise return null.
*/
protected ErrorInfo getErrorInfo(IOException e) {
GoogleJsonError gjre = getDetails(e);
if (gjre != null) {
return getErrorInfo(gjre);
}
return null;
}
开发者ID:GoogleCloudPlatform,项目名称:bigdata-interop,代码行数:12,代码来源:ApiErrorExtractor.java
示例13: googleJsonResponseException
import com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo; //导入依赖的package包/类
/**
* Builds a fake GoogleJsonResponseException for testing API error handling.
*/
private static GoogleJsonResponseException googleJsonResponseException(
int httpStatus, String reason, String message, String httpStatusString) throws IOException {
ErrorInfo errorInfo = new ErrorInfo();
errorInfo.setReason(reason);
errorInfo.setMessage(message);
return googleJsonResponseException(httpStatus, errorInfo, httpStatusString);
}
开发者ID:GoogleCloudPlatform,项目名称:bigdata-interop,代码行数:11,代码来源:ApiErrorExtractorTest.java
示例14: run
import com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo; //导入依赖的package包/类
/**
* Runs this sample.
*
* @param service AdSense service object on which to run the requests.
* @param accountId the ID for the account to be used.
* @param maxPageSize the maximum page size to retrieve.
* @throws Exception
*/
public static void run(AdSense service, String accountId, int maxPageSize) throws Exception {
System.out.println("=================================================================");
System.out.println("Testing error handling");
System.out.println("=================================================================");
try {
// Attempt API call.
service.accounts().adclients().list(accountId).setMaxResults(maxPageSize).execute();
System.out.println("The call succeeded. Please use an invalid, disapproved or " +
"approval-pending AdSense account to test error handling.");
System.out.println();
} catch (GoogleJsonResponseException e) {
// Handle a few known API errors. See full list at
// https://developers.google.com/adsense/management/v1.1/reference/#errors
List<ErrorInfo> errors = e.getDetails().getErrors();
for (ErrorInfo error : errors) {
if (error.getReason().equals("noAdSenseAccount")) {
System.out.println("Error handled! No AdSense account for this user.");
} else if (error.getReason().equals("disapprovedAccount")) {
System.out.println("Error handled! This account is disapproved.");
} else if (error.getReason().equals("accountPendingReview")) {
System.out.println("Error handled! This account is pending review.");
} else {
// Unrecognized reason, so let's use the error message returned by the API.
System.out.println("Unrecognized error, showing system message:");
System.out.println(error.getMessage());
}
}
}
}
开发者ID:googleads,项目名称:googleads-adsense-examples,代码行数:41,代码来源:HandleAccountErrors.java
注:本文中的com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论