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 Object
Contains utility methods for handling partial failure of operations.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classIndicates 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 -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract AbstractErrorUtils.ErrorPath<GoogleAdsErrorT>createErrorPath(GoogleAdsErrorT error, FieldPathElementT errorLocation) protected Iterable<AbstractErrorUtils.ErrorPath<GoogleAdsErrorT>>getErrorPaths(GoogleAdsFailureT googleAdsFailure) getFailedOperationIndices(GoogleAdsFailureT googleAdsFailureT) Provides a convenience method to get distinct failed operation indices.abstract List<FieldPathElementT>getFieldPathElements(GoogleAdsErrorT googleAdsError) Extracts theAbstractErrorUtilsinstances from theAbstractErrorUtils.getGoogleAdsErrors(long operationIndex, com.google.rpc.Status partialFailureStatus) Gets a list of all partial failure error messages for a given response.getGoogleAdsErrors(long operationIndex, GoogleAdsFailureT googleAdsFailure) Return a list ofAbstractErrorUtilsinstances for a given operation index.abstract List<GoogleAdsErrorT>getGoogleAdsErrors(GoogleAdsFailureT googleAdsFailure) Extracts theAbstractErrorUtilsinstances fromAbstractErrorUtils.getGoogleAdsFailure(com.google.protobuf.Any detail) Unpacks a singleAbstractErrorUtilsfrom anAnyinstance.getGoogleAdsFailure(com.google.rpc.Status partialFailureStatus) Unpacks the GoogleAdsFailureT instance form a partial failure status object.abstract Class<GoogleAdsFailureT>Returns theClassinstance forAbstractErrorUtils.booleanisPartialFailureResult(com.google.protobuf.Message message) Checks if a result in a mutate response is a partial failure.
-
Constructor Details
-
AbstractErrorUtils
public AbstractErrorUtils()
-
-
Method Details
-
getGoogleAdsErrors
public 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 supports:GoogleAdsService.mutateGoogleAds(request), where the request contains a list ofMutateOperations named "mutate_operations".ConversionAdjustmentUploadService.uploadConversionAdjustments(request), where the request contains a list ofConversionAdjustments named "conversion_adjustments".UploadClickConversionsRequest.uploadClickConversions(request), where the request contains a list ofClickConversions named "conversions".UploadCallConversionsRequest.uploadCallConversions(request), where the request contains a list ofCallConversions named "conversions".
- 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 List<GoogleAdsErrorT> getGoogleAdsErrors(long operationIndex, GoogleAdsFailureT googleAdsFailure) Return a list ofAbstractErrorUtilsinstances for a given operation index.- See Also:
-
getFailedOperationIndices
Provides a convenience method to get distinct failed operation indices. Returns a list ofLongobjects because this method may be used withBatchJobResultobjects, which have anoperationIndexof typelong.IMPORTANT: Make sure you use
Longobjects to check for the existence of an item in this list. For example, the following lookup will returnfalsedue to autoboxing, even if the list containsLong.valueOf(25).Incorrect approach:
List
failedIndices = getFailedOperationIndices(googleAdsFailure); int intOpIndex = 25; // The JVM will autobox intOpIndex as an Integer, not a Long, so contains(intOpIndex) will // return false. In fact, it will return false for ANY int value because the equals// method ofLongandIntegerreturns false if the argument is not a Long or // is not an Integer, respectively. if (failedIndices.contains(intOpIndex)) { // This block will never execute. // ... handle error }Correct approach. Casts the int index to long so the JVM will autobox into a Long value:
List
failedIndices = getFailedOperationIndices(googleAdsFailure); int intOpIndex = 25; // Casts the int value to a long for correctness. This will also work correctly if the // argument is Long.valueOf(intOpIndex). if (failedIndices.contains((long) intOpIndex)) { // This block will execute if failedIndices contains 25. // ... handle error } -
getGoogleAdsFailure
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.NullPointerException- if detail is null.
-
getGoogleAdsFailure
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.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 Iterable<AbstractErrorUtils.ErrorPath<GoogleAdsErrorT>> getErrorPaths(GoogleAdsFailureT googleAdsFailure) - Parameters:
googleAdsFailure- the failure from which to extractAbstractErrorUtils.ErrorPaths.- Returns:
- all error paths found
-
getFieldPathElements
Extracts theAbstractErrorUtilsinstances from theAbstractErrorUtils.- Parameters:
googleAdsError- the error from which to extract field paths.- Returns:
- the available field paths.
-
getGoogleAdsErrors
Extracts theAbstractErrorUtilsinstances fromAbstractErrorUtils.- Parameters:
googleAdsFailure- the failure from which to extract.- Returns:
- the errors extracted.
-
getGoogleAdsFailureClass
Returns theClassinstance forAbstractErrorUtils. -
createErrorPath
protected abstract AbstractErrorUtils.ErrorPath<GoogleAdsErrorT> createErrorPath(GoogleAdsErrorT error, FieldPathElementT errorLocation)
-