line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CloudHealth::API::ResultParser; |
2
|
2
|
|
|
2
|
|
629
|
use Moo; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
13
|
|
3
|
2
|
|
|
2
|
|
1182
|
use JSON::MaybeXS; |
|
2
|
|
|
|
|
6018
|
|
|
2
|
|
|
|
|
137
|
|
4
|
2
|
|
|
2
|
|
465
|
use CloudHealth::API::Error; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
830
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
has parser => (is => 'ro', default => sub { JSON::MaybeXS->new }); |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub result2return { |
9
|
7
|
|
|
7
|
0
|
25050
|
my ($self, $response) = @_; |
10
|
|
|
|
|
|
|
|
11
|
7
|
100
|
|
|
|
34
|
if ($response->status >= 400) { |
12
|
4
|
|
|
|
|
13
|
return $self->process_error($response); |
13
|
|
|
|
|
|
|
} else { |
14
|
3
|
100
|
|
|
|
15
|
return 1 if (not defined $response->content); |
15
|
2
|
|
|
|
|
7
|
return $self->process_response($response); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub process_response { |
20
|
2
|
|
|
2
|
0
|
5
|
my ($self, $response) = @_; |
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
|
|
3
|
my $struct = eval { |
23
|
2
|
|
|
|
|
26
|
$self->parser->decode($response->content); |
24
|
|
|
|
|
|
|
}; |
25
|
2
|
100
|
|
|
|
30
|
CloudHealth::API::Error->throw( |
26
|
|
|
|
|
|
|
type => 'UnparseableResponse', |
27
|
|
|
|
|
|
|
message => 'Can\'t parse response ' . $response->content . ' with error ' . $@ |
28
|
|
|
|
|
|
|
) if ($@); |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
4
|
return $struct; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Process a response following http://apidocs.cloudhealthtech.com/#documentation_error-codes |
34
|
|
|
|
|
|
|
sub process_error { |
35
|
4
|
|
|
4
|
0
|
9
|
my ($self, $response) = @_; |
36
|
|
|
|
|
|
|
|
37
|
4
|
|
|
|
|
8
|
my $struct = eval { |
38
|
4
|
|
|
|
|
55
|
$self->parser->decode($response->content); |
39
|
|
|
|
|
|
|
}; |
40
|
|
|
|
|
|
|
|
41
|
4
|
50
|
|
|
|
15
|
CloudHealth::API::Error->throw( |
42
|
|
|
|
|
|
|
type => 'UnparseableResponse', |
43
|
|
|
|
|
|
|
message => 'Can\'t parse JSON content', |
44
|
|
|
|
|
|
|
detail => $response->content, |
45
|
|
|
|
|
|
|
) if ($@); |
46
|
|
|
|
|
|
|
|
47
|
4
|
|
|
|
|
6
|
my $message; |
48
|
4
|
100
|
66
|
|
|
23
|
if (defined $struct->{ error }) { |
|
|
100
|
|
|
|
|
|
49
|
2
|
|
|
|
|
6
|
$message = $struct->{ error }; |
50
|
|
|
|
|
|
|
} elsif ($struct->{ errors } and ref($struct->{ errors }) eq 'ARRAY') { |
51
|
1
|
|
|
|
|
4
|
$message = join ',', @{ $struct->{ errors } }; |
|
1
|
|
|
|
|
5
|
|
52
|
|
|
|
|
|
|
} else { |
53
|
1
|
|
|
|
|
4
|
$message = 'No message'; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
4
|
|
|
|
|
42
|
CloudHealth::API::RemoteError->throw( |
57
|
|
|
|
|
|
|
status => $response->status, |
58
|
|
|
|
|
|
|
message => $message, |
59
|
|
|
|
|
|
|
) |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
1; |