本文整理汇总了Java中com.google.api.client.googleapis.json.GoogleJsonError.setMessage方法的典型用法代码示例。如果您正苦于以下问题:Java GoogleJsonError.setMessage方法的具体用法?Java GoogleJsonError.setMessage怎么用?Java GoogleJsonError.setMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.api.client.googleapis.json.GoogleJsonError
的用法示例。
在下文中一共展示了GoogleJsonError.setMessage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: errorWithReasonAndStatus
import com.google.api.client.googleapis.json.GoogleJsonError; //导入方法依赖的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;
}
示例2: googleJsonResponseException
import com.google.api.client.googleapis.json.GoogleJsonError; //导入方法依赖的package包/类
private static GoogleJsonResponseException googleJsonResponseException(
final int status, final ErrorInfo errorInfo, final String httpStatusString)
throws IOException {
final JsonFactory jsonFactory = new JacksonFactory();
HttpTransport transport = new MockHttpTransport() {
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
errorInfo.setFactory(jsonFactory);
GoogleJsonError jsonError = new GoogleJsonError();
jsonError.setCode(status);
jsonError.setErrors(Arrays.asList(errorInfo));
jsonError.setMessage(httpStatusString);
jsonError.setFactory(jsonFactory);
GenericJson errorResponse = new GenericJson();
errorResponse.set("error", jsonError);
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);
}