public class ApiErrorExtractor extends Object
Modifier and Type | Field and Description |
---|---|
static String |
ACCESS_NOT_CONFIGURED_REASON |
static String |
ACCOUNT_DISABLED_REASON |
static String |
FIELD_SIZE_TOO_LARGE_REASON |
static String |
GLOBAL_DOMAIN |
static ApiErrorExtractor |
INSTANCE
Singleton instance of the ApiErrorExtractor.
|
static String |
QUOTA_EXCEEDED_REASON |
static String |
RATE_LIMITED_REASON |
static String |
RESOURCE_NOT_READY_REASON |
static int |
STATUS_CODE_RANGE_NOT_SATISFIABLE |
static String |
USAGE_LIMITS_DOMAIN |
static String |
USER_PROJECT_MISSING_MESSAGE |
static String |
USER_RATE_LIMITED_REASON |
Constructor and Description |
---|
ApiErrorExtractor() |
Modifier and Type | Method and Description |
---|---|
boolean |
accessDenied(IOException e)
Determines if the given exception indicates 'access denied'.
|
boolean |
accessDeniedNonRecoverable(IOException e)
Determines if the exception is a non-recoverable access denied code (such as account closed or
marked for deletion).
|
boolean |
badRequest(IOException e)
Determines if the given exception indicates bad request.
|
boolean |
clientError(IOException e)
Determines if the exception is a client error.
|
boolean |
fieldSizeTooLarge(IOException e)
Determines if the given exception indicates 'field size too large'.
|
String |
getDebugInfo(IOException e) |
protected com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo |
getErrorInfo(IOException e)
Get the first ErrorInfo from an IOException if it is an instance of
GoogleJsonResponseException, otherwise return null.
|
String |
getErrorMessage(IOException e)
Extracts the error message.
|
protected int |
getHttpStatusCode(com.google.api.client.googleapis.json.GoogleJsonResponseException e)
Returns HTTP status code from the given exception.
|
protected com.google.api.client.googleapis.json.GoogleJsonError |
getJsonError(IOException e)
If the exception is a GoogleJsonResponseException, get the error details, else return null.
|
static com.google.api.client.googleapis.json.GoogleJsonResponseException |
getJsonResponseException(Throwable throwable) |
boolean |
internalServerError(IOException e)
Determines if the exception is an internal server error.
|
boolean |
itemAlreadyExists(IOException e)
Determines if the given exception indicates 'item already exists'.
|
boolean |
itemNotFound(IOException e)
Determines if the given exception indicates 'item not found'.
|
boolean |
preconditionNotMet(IOException e)
Determines if the given IOException indicates 'precondition not met' Recursively checks
getCause() if outer exception isn't an instance of the correct class.
|
boolean |
quotaExceeded(IOException e)
Determines if a given Throwable is caused by Quota Exceeded.
|
boolean |
rangeNotSatisfiable(IOException e)
Determines if the given exception indicates 'range not satisfiable'.
|
boolean |
rateLimited(IOException e)
Determines if a given Throwable is caused by a rate limit being applied.
|
protected boolean |
recursiveCheckForCode(IOException e,
int code)
Recursively checks getCause() if outer exception isn't an instance of the correct class.
|
boolean |
requestFailure(IOException e)
Determines if the given exception indicates intermittent request failure or failure caused by
user error.
|
boolean |
resourceNotReady(IOException e)
Determines if the given exception indicates 'resource not ready'.
|
IOException |
toUserPresentableException(IOException e,
String action)
Converts the exception to a user-presentable error message.
|
String |
toUserPresentableMessage(IOException e)
|
String |
toUserPresentableMessage(IOException e,
String action)
Converts the exception to a user-presentable error message.
|
boolean |
unauthorized(IOException e)
Determines if the given exception indicates the request was unauthenticated.
|
boolean |
userProjectMissing(IOException e)
Determines if the given exception indicates that 'userProject' is missing in request.
|
public static final ApiErrorExtractor INSTANCE
public static final int STATUS_CODE_RANGE_NOT_SATISFIABLE
public static final String GLOBAL_DOMAIN
public static final String USAGE_LIMITS_DOMAIN
public static final String RATE_LIMITED_REASON
public static final String USER_RATE_LIMITED_REASON
public static final String QUOTA_EXCEEDED_REASON
public static final String ACCOUNT_DISABLED_REASON
public static final String ACCESS_NOT_CONFIGURED_REASON
public static final String RESOURCE_NOT_READY_REASON
public static final String FIELD_SIZE_TOO_LARGE_REASON
public static final String USER_PROJECT_MISSING_MESSAGE
public boolean requestFailure(IOException e)
public boolean accessDenied(IOException e)
Warning: this method only checks for access denied status code, however this may include
potentially recoverable reason codes such as rate limiting. For alternative, see accessDeniedNonRecoverable(IOException)
.
public boolean badRequest(IOException e)
public boolean unauthorized(IOException e)
public boolean accessDeniedNonRecoverable(IOException e)
public boolean clientError(IOException e)
public boolean internalServerError(IOException e)
public boolean itemAlreadyExists(IOException e)
public boolean itemNotFound(IOException e)
public boolean fieldSizeTooLarge(IOException e)
public boolean resourceNotReady(IOException e)
public boolean preconditionNotMet(IOException e)
public boolean rangeNotSatisfiable(IOException e)
public boolean rateLimited(IOException e)
e
- The Throwable to check.public boolean quotaExceeded(IOException e)
public boolean userProjectMissing(IOException e)
public String getErrorMessage(IOException e)
public IOException toUserPresentableException(IOException e, String action) throws IOException
e
- the exceptionaction
- the description of the action being performed at the time of error.IOException
toUserPresentableMessage(IOException, String)
public String toUserPresentableMessage(IOException e, @Nullable String action)
public String toUserPresentableMessage(IOException e)
@Nullable public String getDebugInfo(IOException e)
protected int getHttpStatusCode(com.google.api.client.googleapis.json.GoogleJsonResponseException e)
Note: GoogleJsonResponseException.getStatusCode() method is marked final therefore it cannot be mocked using Mockito. We use this helper so that we can override it in tests.
@Nullable protected com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo getErrorInfo(IOException e)
@Nullable protected com.google.api.client.googleapis.json.GoogleJsonError getJsonError(IOException e)
protected boolean recursiveCheckForCode(IOException e, int code)
Copyright © 2023. All rights reserved.