Package com.google.cloud.hadoop.util
Class ApiErrorExtractor
java.lang.Object
com.google.cloud.hadoop.util.ApiErrorExtractor
Translates exceptions from API calls into higher-level meaning, while allowing injectability for
testing how API errors are handled.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final ApiErrorExtractorSingleton instance of the ApiErrorExtractor.static final Stringstatic final Stringstatic final Stringstatic final intstatic final Stringstatic final Stringstatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanDetermines if the given exception indicates 'access denied'.booleanDetermines if the exception is a non-recoverable access denied code (such as account closed or marked for deletion).booleanDetermines if the given exception indicates bad request.booleanDetermines if the exception is a client error.booleanDetermines if the given exception indicates 'field size too large'.protected com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfoGet the first ErrorInfo from an IOException if it is an instance of GoogleJsonResponseException, otherwise return null.Extracts the error message.static com.google.api.client.http.HttpResponseExceptiongetHttpResponseException(Throwable throwable) protected intgetHttpStatusCode(com.google.api.client.http.HttpResponseException e) Returns HTTP status code from the given exception.protected com.google.api.client.googleapis.json.GoogleJsonErrorIf the exception is a GoogleJsonResponseException, get the error details, else return null.static com.google.api.client.googleapis.json.GoogleJsonResponseExceptiongetJsonResponseException(Throwable throwable) booleanDetermines if the exception is an internal server error.booleanDetermines if the given exception indicates 'item already exists'.booleanDetermines if the given exception indicates 'item not found'.booleanDetermines if the given IOException indicates 'precondition not met' Recursively checks getCause() if outer exception isn't an instance of the correct class.booleanDetermines if a given Throwable is caused by Quota Exceeded.booleanDetermines if the given exception indicates 'range not satisfiable'.booleanDetermines if a given Throwable is caused by a rate limit being applied.protected booleanrecursiveCheckForCode(IOException e, int code) Recursively checks getCause() if outer exception isn't an instance of the correct class.booleanDetermines if the given exception indicates intermittent request failure or failure caused by user error.booleanDetermines if the given exception indicates 'resource not ready'.toUserPresentableException(IOException e, String action) Converts the exception to a user-presentable error message.toUserPresentableMessage(IOException e, String action) Converts the exception to a user-presentable error message.booleanDetermines if the given exception indicates the request was unauthenticated.booleanDetermines if the given exception indicates that 'userProject' is missing in request.
-
Field Details
-
INSTANCE
Singleton instance of the ApiErrorExtractor. -
STATUS_CODE_RANGE_NOT_SATISFIABLE
public static final int STATUS_CODE_RANGE_NOT_SATISFIABLE- See Also:
-
GLOBAL_DOMAIN
- See Also:
-
USAGE_LIMITS_DOMAIN
- See Also:
-
RATE_LIMITED_REASON
- See Also:
-
USER_RATE_LIMITED_REASON
- See Also:
-
QUOTA_EXCEEDED_REASON
- See Also:
-
ACCOUNT_DISABLED_REASON
- See Also:
-
ACCESS_NOT_CONFIGURED_REASON
- See Also:
-
RESOURCE_NOT_READY_REASON
- See Also:
-
FIELD_SIZE_TOO_LARGE_REASON
- See Also:
-
USER_PROJECT_MISSING_MESSAGE
- See Also:
-
-
Constructor Details
-
ApiErrorExtractor
public ApiErrorExtractor()
-
-
Method Details
-
requestFailure
Determines if the given exception indicates intermittent request failure or failure caused by user error. -
accessDenied
Determines if the given exception indicates 'access denied'. Recursively checks getCause() if outer exception isn't an instance of the correct class.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). -
badRequest
Determines if the given exception indicates bad request. -
unauthorized
Determines if the given exception indicates the request was unauthenticated. This can be caused by attaching invalid credentials to a request. -
accessDeniedNonRecoverable
Determines if the exception is a non-recoverable access denied code (such as account closed or marked for deletion). -
clientError
Determines if the exception is a client error. -
internalServerError
Determines if the exception is an internal server error. -
itemAlreadyExists
Determines if the given exception indicates 'item already exists'. Recursively checks getCause() if outer exception isn't an instance of the correct class. -
itemNotFound
Determines if the given exception indicates 'item not found'. Recursively checks getCause() if outer exception isn't an instance of the correct class. -
fieldSizeTooLarge
Determines if the given exception indicates 'field size too large'. Recursively checks getCause() if outer exception isn't an instance of the correct class. -
resourceNotReady
Determines if the given exception indicates 'resource not ready'. Recursively checks getCause() if outer exception isn't an instance of the correct class. -
preconditionNotMet
Determines if the given IOException indicates 'precondition not met' Recursively checks getCause() if outer exception isn't an instance of the correct class. -
rangeNotSatisfiable
Determines if the given exception indicates 'range not satisfiable'. Recursively checks getCause() if outer exception isn't an instance of the correct class. -
rateLimited
Determines if a given Throwable is caused by a rate limit being applied. Recursively checks getCause() if outer exception isn't an instance of the correct class.- Parameters:
e- The Throwable to check.- Returns:
- True if the Throwable is a result of rate limiting being applied.
-
quotaExceeded
Determines if a given Throwable is caused by Quota Exceeded. Recursively checks getCause() if outer exception isn't an instance of the correct class. -
userProjectMissing
Determines if the given exception indicates that 'userProject' is missing in request. Recursively checks getCause() if outer exception isn't an instance of the correct class. -
getErrorMessage
Extracts the error message. -
toUserPresentableException
Converts the exception to a user-presentable error message. Specifically, extracts message field for HTTP 4xx codes, and creates a generic "Internal Server Error" for HTTP 5xx codes.- Parameters:
e- the exceptionaction- the description of the action being performed at the time of error.- Throws:
IOException- See Also:
-
toUserPresentableMessage
Converts the exception to a user-presentable error message. Specifically, extracts message field for HTTP 4xx codes, and creates a generic "Internal Server Error" for HTTP 5xx codes. -
toUserPresentableMessage
-
getDebugInfo
-
getHttpStatusCode
protected int getHttpStatusCode(com.google.api.client.http.HttpResponseException e) Returns HTTP status code from the given exception.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.
-
getErrorInfo
@Nullable 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. -
getJsonError
@Nullable protected com.google.api.client.googleapis.json.GoogleJsonError getJsonError(IOException e) If the exception is a GoogleJsonResponseException, get the error details, else return null. -
recursiveCheckForCode
Recursively checks getCause() if outer exception isn't an instance of the correct class. -
getJsonResponseException
@Nullable public static com.google.api.client.googleapis.json.GoogleJsonResponseException getJsonResponseException(Throwable throwable) -
getHttpResponseException
@Nullable public static com.google.api.client.http.HttpResponseException getHttpResponseException(Throwable throwable)
-