Class AbstractErrorUtils<GoogleAdsFailureT extends com.google.protobuf.Message,GoogleAdsErrorT extends com.google.protobuf.Message,FieldPathElementT extends com.google.protobuf.Message>
- java.lang.Object
-
- com.google.ads.googleads.lib.utils.AbstractErrorUtils<GoogleAdsFailureT,GoogleAdsErrorT,FieldPathElementT>
-
public abstract class AbstractErrorUtils<GoogleAdsFailureT extends com.google.protobuf.Message,GoogleAdsErrorT extends com.google.protobuf.Message,FieldPathElementT extends com.google.protobuf.Message> extends java.lang.ObjectContains utility methods for handling partial failure of operations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAbstractErrorUtils.DeserializeExceptionIndicates an error occurred deserializing an API error object.protected static classAbstractErrorUtils.ErrorPath<GoogleAdsErrorType extends com.google.protobuf.Message>Wrapper around a (@link GoogleAdsErrorT} specifying the location the error occurred, if available.
-
Constructor Summary
Constructors Constructor Description AbstractErrorUtils()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract AbstractErrorUtils.ErrorPath<GoogleAdsErrorT>createErrorPath(GoogleAdsErrorT error, FieldPathElementT errorLocation)protected java.lang.Iterable<AbstractErrorUtils.ErrorPath>getErrorPaths(GoogleAdsFailureT googleAdsFailure)java.util.List<java.lang.Long>getFailedOperationIndices(GoogleAdsFailureT googleAdsFailureT)Provides a convenience method to get all failed operation indices.abstract java.util.List<FieldPathElementT>getFieldPathElements(GoogleAdsErrorT googleAdsError)Extracts theAbstractErrorUtilsinstances from theAbstractErrorUtils.java.util.List<GoogleAdsErrorT>getGoogleAdsErrors(long operationIndex, com.google.rpc.Status partialFailureStatus)Gets a list of all partial failure error messages for a given response.java.util.List<GoogleAdsErrorT>getGoogleAdsErrors(long operationIndex, GoogleAdsFailureT googleAdsFailure)Return a list ofAbstractErrorUtilsinstances for a given operation index.abstract java.util.List<GoogleAdsErrorT>getGoogleAdsErrors(GoogleAdsFailureT googleAdsFailure)Extracts theAbstractErrorUtilsinstances fromAbstractErrorUtils.GoogleAdsFailureTgetGoogleAdsFailure(com.google.protobuf.Any detail)Unpacks a singleAbstractErrorUtilsfrom anAnyinstance.GoogleAdsFailureTgetGoogleAdsFailure(com.google.rpc.Status partialFailureStatus)Unpacks the GoogleAdsFailureT instance form a partial failure status object.abstract java.lang.Class<GoogleAdsFailureT>getGoogleAdsFailureClass()Returns theClassinstance forAbstractErrorUtils.booleanisPartialFailureResult(com.google.protobuf.Message message)Checks if a result in a mutate response is a partial failure.
-
-
-
Method Detail
-
getGoogleAdsErrors
public java.util.List<GoogleAdsErrorT> getGoogleAdsErrors(long operationIndex, com.google.rpc.Status partialFailureStatus) throws com.google.protobuf.InvalidProtocolBufferException
Gets a list of all partial failure error messages for a given response. Operations are indexed from 0.For example, given the following Failure:
A singleerrors { message: "Too low." location { field_path_elements { field_name: "operations" index { value: 1 } } field_path_elements { field_name: "create" } field_path_elements { field_name: "campaign" } } } errors { message: "Too low." location { field_path_elements { field_name: "operations" index { value: 2 } } field_path_elements { field_name: "create" } field_path_elements { field_name: "campaign" } } }AbstractErrorUtilsinstance would be returned for operation index 1 and 2, and an empty list otherwise.This method supports
XXXService.mutate(request)where the request contains a list of operations named "operations". It also supportsGoogleAdsService.mutateGoogleAds(request), where the request contains a list ofMutateOperations named "mutate_operations".- Parameters:
operationIndex- the index of the operation, starting from 0.partialFailureStatus- a partialFailure status, with the detail list containingAbstractErrorUtilsinstances.- Returns:
- a list containing the
AbstractErrorUtilsinstances for a given operation index. - Throws:
com.google.protobuf.InvalidProtocolBufferException- if not able to unpack the protocol buffer. This is most likely due to using the wrong version of ErrorUtils being used with the API response.
-
getGoogleAdsErrors
public java.util.List<GoogleAdsErrorT> getGoogleAdsErrors(long operationIndex, GoogleAdsFailureT googleAdsFailure)
Return a list ofAbstractErrorUtilsinstances for a given operation index.- See Also:
getGoogleAdsErrors(long, Status)
-
getFailedOperationIndices
public java.util.List<java.lang.Long> getFailedOperationIndices(GoogleAdsFailureT googleAdsFailureT)
Provides a convenience method to get all failed operation indices.
-
getGoogleAdsFailure
public GoogleAdsFailureT getGoogleAdsFailure(com.google.protobuf.Any detail)
Unpacks a singleAbstractErrorUtilsfrom anAnyinstance.- Throws:
AbstractErrorUtils.DeserializeException- if anInvalidProtocolBufferExceptionis encountered. This would indicate that the detail object was not-null, but the contents couldn't be deserialized to the target type. This may indicate that the target type is incorrect, or that the content of the Any message is incorrect.java.lang.NullPointerException- if detail is null.
-
getGoogleAdsFailure
public GoogleAdsFailureT getGoogleAdsFailure(com.google.rpc.Status partialFailureStatus)
Unpacks the GoogleAdsFailureT instance form a partial failure status object.The status object contains a details repeated field. This contains at most 1 Any protos which encode a GoogleAdsFailure instance.
- Parameters:
partialFailureStatus- the partial failure Status object returned in the repsponse.- Returns:
- the GoogleAdsFailure instance describing the partial failures, or null if none is found.
- Throws:
AbstractErrorUtils.DeserializeException- if anInvalidProtocolBufferExceptionis encountered.java.lang.NullPointerException- if partialFailureStatus is null.
-
isPartialFailureResult
public boolean isPartialFailureResult(com.google.protobuf.Message message)
Checks if a result in a mutate response is a partial failure.
-
getErrorPaths
protected java.lang.Iterable<AbstractErrorUtils.ErrorPath> getErrorPaths(GoogleAdsFailureT googleAdsFailure)
- Parameters:
googleAdsFailure- the failure from which to extractAbstractErrorUtils.ErrorPaths.- Returns:
- all error paths found
-
getFieldPathElements
public abstract java.util.List<FieldPathElementT> getFieldPathElements(GoogleAdsErrorT googleAdsError)
Extracts theAbstractErrorUtilsinstances from theAbstractErrorUtils.- Parameters:
googleAdsError- the error from which to extract field paths.- Returns:
- the available field paths.
-
getGoogleAdsErrors
public abstract java.util.List<GoogleAdsErrorT> getGoogleAdsErrors(GoogleAdsFailureT googleAdsFailure)
Extracts theAbstractErrorUtilsinstances fromAbstractErrorUtils.- Parameters:
googleAdsFailure- the failure from which to extract.- Returns:
- the errors extracted.
-
getGoogleAdsFailureClass
public abstract java.lang.Class<GoogleAdsFailureT> getGoogleAdsFailureClass()
Returns theClassinstance forAbstractErrorUtils.
-
createErrorPath
protected abstract AbstractErrorUtils.ErrorPath<GoogleAdsErrorT> createErrorPath(GoogleAdsErrorT error, FieldPathElementT errorLocation)
-
-