本文整理汇总了Java中com.google.api.client.googleapis.json.GoogleJsonError.getCode方法的典型用法代码示例。如果您正苦于以下问题:Java GoogleJsonError.getCode方法的具体用法?Java GoogleJsonError.getCode怎么用?Java GoogleJsonError.getCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.api.client.googleapis.json.GoogleJsonError
的用法示例。
在下文中一共展示了GoogleJsonError.getCode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: blobExists
import com.google.api.client.googleapis.json.GoogleJsonError; //导入方法依赖的package包/类
/**
* Returns true if the blob exists in the bucket
*
* @param blobName name of the blob
* @return true if the blob exists, false otherwise
*/
boolean blobExists(String blobName) throws IOException {
try {
StorageObject blob = SocketAccess.doPrivilegedIOException(() -> client.objects().get(bucket, blobName).execute());
if (blob != null) {
return Strings.hasText(blob.getId());
}
} catch (GoogleJsonResponseException e) {
GoogleJsonError error = e.getDetails();
if ((e.getStatusCode() == HTTP_NOT_FOUND) || ((error != null) && (error.getCode() == HTTP_NOT_FOUND))) {
return false;
}
throw e;
}
return false;
}
示例2: delete
import com.google.api.client.googleapis.json.GoogleJsonError; //导入方法依赖的package包/类
@Override
public boolean delete(Path path, boolean recursive) throws IOException {
Preconditions.checkArgument(recursive, "Non-recursive is not supported.");
String fileId = toFileId(path);
LOG.debug("Deleting file: " + fileId);
try {
client.files().delete(fileId).execute();
} catch (GoogleJsonResponseException e) {
GoogleJsonError error = e.getDetails();
if (404 == error.getCode()) { //Non-existing file id
return false;
}
throw e;
}
return true;
}
示例3: checkGoogleJsonResponseException
import com.google.api.client.googleapis.json.GoogleJsonError; //导入方法依赖的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;
}
}
示例4: readBlob
import com.google.api.client.googleapis.json.GoogleJsonError; //导入方法依赖的package包/类
/**
* Returns an {@link java.io.InputStream} for a given blob
*
* @param blobName name of the blob
* @return an InputStream
*/
InputStream readBlob(String blobName) throws IOException {
try {
return SocketAccess.doPrivilegedIOException(() -> {
Storage.Objects.Get object = client.objects().get(bucket, blobName);
return object.executeMediaAsInputStream();
});
} catch (GoogleJsonResponseException e) {
GoogleJsonError error = e.getDetails();
if ((e.getStatusCode() == HTTP_NOT_FOUND) || ((error != null) && (error.getCode() == HTTP_NOT_FOUND))) {
throw new NoSuchFileException(e.getMessage());
}
throw e;
}
}
示例5: addMemberToGroup
import com.google.api.client.googleapis.json.GoogleJsonError; //导入方法依赖的package包/类
@Override
public void addMemberToGroup(String groupKey, String email, Role role) throws IOException {
// Documentation for this API call:
// https://developers.google.com/admin-sdk/directory/v1/reference/members/insert
Member member = new Member();
member.setEmail(email);
member.setRole(role.toString());
try {
directory.members().insert(groupKey, member).execute();
} catch (GoogleJsonResponseException e) {
// If the member is already in the group, ignore the error, get the existing member, and
// return it.
GoogleJsonError err = e.getDetails();
if (err.getCode() == SC_NOT_FOUND && err.getMessage().equals(GROUP_NOT_FOUND_MSG)) {
logger.infofmt(
e,
"Creating group %s during addition of member %s because the group doesn't exist.",
groupKey,
email);
createGroup(groupKey);
addMemberToGroup(groupKey, email, role);
} else if (err.getCode() == SC_NOT_FOUND && err.getMessage().equals(MEMBER_NOT_FOUND_MSG)) {
throw new RuntimeException(String.format(
"Adding member %s to group %s failed because the member wasn't found.",
email,
groupKey), e);
} else if (err.getCode() == SC_CONFLICT
&& err.getMessage().equals(MEMBER_ALREADY_EXISTS_MSG)) {
// This error case usually happens when an email address is already a member of the gorup,
// but it is bouncing incoming emails. It won't show up in the members list API call, but
// will throw a "Member already exists" error message if you attempt to add it again. The
// correct thing to do is log an info message when this happens and then ignore it.
logger.infofmt(
e,
"Could not add email %s to group %s because it is already a member "
+ "(likely because the email address is bouncing incoming messages).",
email,
groupKey);
} else {
throw e;
}
}
}
示例6: itemNotFound
import com.google.api.client.googleapis.json.GoogleJsonError; //导入方法依赖的package包/类
/**
* Determines if the given GoogleJsonError indicates 'item not found'.
*/
public boolean itemNotFound(GoogleJsonError e) {
return e.getCode() == HttpStatusCodes.STATUS_CODE_NOT_FOUND;
}
示例7: preconditionNotMet
import com.google.api.client.googleapis.json.GoogleJsonError; //导入方法依赖的package包/类
/**
* Determines if the given GoogleJsonError indicates 'precondition not met'
*/
public boolean preconditionNotMet(GoogleJsonError e) {
return e.getCode() == STATUS_CODE_PRECONDITION_FAILED;
}