GoogleAdsException.pm

filter: Statementstmt 100% 40 / 40 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 50.0% 1 / 2 totaltotal 98.0% 50 / 51 CC 3 SCAR 5.1
CC
3
Cov
100%
get_google_ads_failure
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.7
« V26/Services/ReachPlanService.pm ↑ Summary V23/Services/BenchmarksService.pm »
1 # Copyright 2019, Google LLC
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 #
15 # The class represents the exception message from Google Ads API server.
16  
17 package Google::Ads::GoogleAds::GoogleAdsException;
18  
19 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 5 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 # The following needs to be on one line because CPAN uses a particularly hacky
24 # eval() to determine module versions.
25 5 ▶use Google::Ads::GoogleAds::Constants; our $VERSION = ${Google::Ads::GoogleAds::Constants::VERSION};
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 5 ▶use Class::Std::Fast constructor => 'none';
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 # Class::Std-style attributes. Most values are read from googleads.properties file.
30 # These need to go in the same line for older Perl interpreters to understand.
31 5 my %code_of : ATTR(:get<code> :default<>);
32 5 my %message_of : ATTR(:get<message> :default<>);
33 5 my %status_of : ATTR(:get<status> :default<>);
34 5 my %details_of : ATTR(:get<details> :default<>);
35  
36 3 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
37 3 my $self = bless \do { my $exception = Class::Std::Fast::ID }, shift;
38 3 my $ident = ident $self;
39  
40 3 my $response_body = shift;
41 3 my $error = $response_body->{error};
42  
43 3 $code_of{$ident} = $error->{code};
44 3 $message_of{$ident} = $error->{message};
45 3 $status_of{$ident} = $error->{status};
46  
47 # The details may contain GoogleAdsFailure or standard GRPC errors, e.g.
48 # BadRequest, PreconditionFailure, QuotaFailure.
49 3 $details_of{$ident} = $error->{details};
50  
51 3 return $self;
52 }
53  
54 # Extracts the GoogleAdsFailure object from the details hash.
55 3 ▶sub get_google_ads_failure {
Subroutine get_google_ads_failure: called CC=3 SCAR=11.0
Pod documented
56 3 my $self = shift;
57  
58 3 foreach my $detail (@{$self->get_details}) {
59 3 my $type = $detail->{"\@type"};
60 3 ▶ if ($type =~ /google.ads.googleads.v(\d+).errors.GoogleAdsFailure/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /google.ads.googleads.v(\d+).errors.GoogleAdsFailure/) 2 1 3
61 2 my $class =
62 sprintf(
63 Google::Ads::GoogleAds::Constants::GOOGLE_ADS_FAILURE_CLASS_NAME,
64 $1);
65  
66 # Require class name.
67 2 eval("require $class");
68 2 return $class->new({errors => $detail->{errors}});
69 }
70 }
71 1 return undef;
72 }
73  
74 5 1;
75  
76 =pod
77  
78 =head1 NAME
79  
80 Google::Ads::GoogleAds::GoogleAdsException
81  
82 =head1 SYNOPSIS
83  
84 my $api_client = Google::Ads::GoogleAds::Client->new();
85 $api_client->set_die_on_faults(0);
86  
87 my $response = $api_client->AdGroupAdService()->mutate($mutate_request);
88  
89 if ($response->isa("Google::Ads::GoogleAds::GoogleAdsException")) {
90 my $google_ads_failure = $response->get_google_ads_failure();
91  
92 # Do something with the GoogleAdsFailure object.
93 }
94  
95 =head1 DESCRIPTION
96  
97 The class represents the exception message from Google Ads API server.
98  
99 =head1 ATTRIBUTES
100  
101 There is a get_ method associated with each attribute for retrieving them dynamically.
102  
103 =head2 code
104  
105 The HTTP response code.
106  
107 =head2 message
108  
109 A human-readable description of this exception.
110  
111 =head2 status
112  
113 The status code of this exception.
114  
115 =head2 details
116  
117 The detailed information of this exception, which may contain failure messages.
118  
119 =head1 METHODS
120  
121 =head2 get_google_ads_failure
122  
123 Extracts a L<Google::Ads::GoogleAds::V26::Errors::GoogleAdsFailure> object from the
124 L</details> attribute of the current exception object.
125  
126 =head3 Returns
127  
128 A L<Google::Ads::GoogleAds::V26::Errors::GoogleAdsFailure> object or undef if not found.
129  
130 =head1 LICENSE AND COPYRIGHT
131  
132 Copyright 2019 Google LLC
133  
134 Licensed under the Apache License, Version 2.0 (the "License");
135 you may not use this file except in compliance with the License.
136 You may obtain a copy of the License at
137  
138 http://www.apache.org/licenses/LICENSE-2.0
139  
140 Unless required by applicable law or agreed to in writing, software
141 distributed under the License is distributed on an "AS IS" BASIS,
142 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
143 See the License for the specific language governing permissions and
144 limitations under the License.
145  
146 =head1 REPOSITORY INFORMATION
147  
148 $Rev: $
149 $LastChangedBy: $
150 $Id: $
151  
152 =cut
« V26/Services/ReachPlanService.pm ↑ Summary V23/Services/BenchmarksService.pm »