Class AbstractErrorUtils<GoogleAdsFailureT extends com.google.protobuf.Message,​GoogleAdsErrorT extends com.google.protobuf.Message,​FieldPathElementT extends com.google.protobuf.Message>


  • 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.Object
    Contains utility methods for handling partial failure of operations.
    • Constructor Detail

      • AbstractErrorUtils

        public AbstractErrorUtils()
    • 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:

           
             errors {
               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"
                 }
               }
             }
           
         
        A single AbstractErrorUtils instance 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 of MutateOperations named "mutate_operations".

        Parameters:
        operationIndex - the index of the operation, starting from 0.
        partialFailureStatus - a partialFailure status, with the detail list containing AbstractErrorUtils instances.
        Returns:
        a list containing the AbstractErrorUtils instances 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.
      • 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 single AbstractErrorUtils from an Any instance.
        Throws:
        AbstractErrorUtils.DeserializeException - if an InvalidProtocolBufferException is 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 an InvalidProtocolBufferException is 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.