line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Amazon::API::Error; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
24
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
84
|
|
4
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
81
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
23
|
use parent qw( Class::Accessor::Fast ); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
36
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
2139
|
use Data::Dumper; |
|
3
|
|
|
|
|
20468
|
|
|
3
|
|
|
|
|
186
|
|
9
|
3
|
|
|
3
|
|
1420
|
use English qw{ -no_match_vars }; |
|
3
|
|
|
|
|
6966
|
|
|
3
|
|
|
|
|
16
|
|
10
|
3
|
|
|
3
|
|
3713
|
use JSON qw{ decode_json }; |
|
3
|
|
|
|
|
32142
|
|
|
3
|
|
|
|
|
48
|
|
11
|
3
|
|
|
3
|
|
389
|
use Scalar::Util qw{ reftype }; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
144
|
|
12
|
3
|
|
|
3
|
|
2452
|
use XML::Simple qw{ XMLin }; |
|
3
|
|
|
|
|
26089
|
|
|
3
|
|
|
|
|
21
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
__PACKAGE__->follow_best_practice; |
15
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/error api message_raw response content_type/); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '2.0.10'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
######################################################################## |
20
|
|
|
|
|
|
|
sub new { |
21
|
|
|
|
|
|
|
######################################################################## |
22
|
0
|
|
|
0
|
1
|
|
my ( $class, @options ) = @_; |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new(@options); |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
$self->_set_message; |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
return $self; |
29
|
|
|
|
|
|
|
} ## end sub new |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
############################################################### |
32
|
|
|
|
|
|
|
sub _set_message { |
33
|
|
|
|
|
|
|
############################################################### |
34
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $raw_message = $self->get_message_raw; |
37
|
0
|
|
|
|
|
|
my $message; |
38
|
|
|
|
|
|
|
|
39
|
0
|
0
|
|
|
|
|
if ($raw_message) { |
40
|
|
|
|
|
|
|
|
41
|
0
|
0
|
|
|
|
|
if ( $self->get_content_type =~ /xml/xmsi ) { |
|
|
0
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
$message = eval { return XMLin($raw_message); }; |
|
0
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
elsif ( $self->get_content_type =~ /json/xmsi ) { |
45
|
0
|
|
|
|
|
|
$message = eval { return decode_json($raw_message); }; |
|
0
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# try a little harder... |
49
|
0
|
0
|
0
|
|
|
|
if ( !$message || $EVAL_ERROR ) { |
50
|
0
|
|
|
|
|
|
$message = eval { return decode_json($raw_message); }; |
|
0
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
0
|
0
|
0
|
|
|
|
if ( !$message || $EVAL_ERROR ) { |
53
|
0
|
0
|
|
|
|
|
if ( $raw_message =~ /^\s*\</xsm ) { |
54
|
0
|
|
|
|
|
|
$message = eval { return XMLin($raw_message); }; |
|
0
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} ## end if ( !$message || $EVAL_ERROR) |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
} ## end if ($raw_message) |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
0
|
|
|
|
$message = $message || $raw_message; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
$self->set_response($message); |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
return $message; |
66
|
|
|
|
|
|
|
} ## end sub _set_message |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
############################################################### |
69
|
|
|
|
|
|
|
sub get_aws_api { |
70
|
|
|
|
|
|
|
############################################################### |
71
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
0
|
|
|
|
my $api = eval { return $self->get_api->get_api || ref( $self->get_api ); }; |
|
0
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
return $api; |
76
|
|
|
|
|
|
|
} ## end sub get_aws_api |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=pod |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 NAME |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
C<Amazon::API::Error> |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 SYNOPSIS |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
my $result = eval { |
91
|
|
|
|
|
|
|
decode_json( |
92
|
|
|
|
|
|
|
$cwe->PutPermission( |
93
|
|
|
|
|
|
|
{ Action => "PutEvents", |
94
|
|
|
|
|
|
|
Principal => "123454657889012", |
95
|
|
|
|
|
|
|
StatementId => "12345" |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
); |
98
|
|
|
|
|
|
|
}; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
print Dumper( [ $@->get_response, $@->get_error ] ) |
101
|
|
|
|
|
|
|
if $@ && ref($@) =~ /API::Error/; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 DESCRIPTION |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Error object that contains that status code and the error message |
106
|
|
|
|
|
|
|
contained in the body of the response to the API call. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 METHODS AND SUBROUTINEs |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 get_error |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Returns the HTTP status code returned by the API call. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 get_response |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Returns a decoded response. Usually a hash. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 get_message_raw |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Returns the content of the body of the error response. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 get_content_type |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Returns the Content-Type of the response. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 get_aws_api |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Returns the API that was called that generated the error. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 NOTES |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
An example response: |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?> |
135
|
|
|
|
|
|
|
<Response><Errors><Error><Code>UnauthorizedOperation</Code><Message>You are not authorized to perform this operation.</Message></Error></Errors><RequestID>599b0f86-4668-4adb-b493-552d6039fcd1</RequestID></Response> |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
This module is free software. It may be used, redistributed and/or |
140
|
|
|
|
|
|
|
modified under the same terms as Perl itself. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 AUTHOR |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Rob Lauer - <rlauer6@comcast.net> |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 SEE OTHER |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
C<Amazon::API> |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |