File Coverage

blib/lib/CloudHealth/API/Error.pm
Criterion Covered Total %
statement 12 18 66.6
branch 0 2 0.0
condition n/a
subroutine 4 6 66.6
pod 1 2 50.0
total 17 28 60.7


line stmt bran cond sub pod time code
1             package CloudHealth::API::Error;
2 3     3   33 use Moo;
  3         7  
  3         34  
3 3     3   1233 use Types::Standard qw/Str/;
  3         7  
  3         35  
4             extends 'Throwable::Error';
5              
6             has type => (is => 'ro', isa => Str, required => 1);
7             has detail => (is => 'ro');
8              
9             sub header {
10 0     0 0   my $self = shift;
11 0           return sprintf "Exception with type: %s: %s", $self->type, $self->message;
12             }
13              
14             sub as_string {
15 0     0 1   my $self = shift;
16 0 0         if (defined $self->detail) {
17 0           return sprintf "%s\nDetail: %s", $self->header, $self->detail;
18             } else {
19 0           return $self->header;
20             }
21             }
22              
23             package CloudHealth::API::RemoteError;
24 3     3   2507 use Moo;
  3         6  
  3         14  
25 3     3   1001 use Types::Standard qw/Int/;
  3         7  
  3         12  
26             extends 'CloudHealth::API::Error';
27              
28             has '+type' => (default => sub { 'Remote' });
29             has status => (is => 'ro', isa => Int, required => 1);
30              
31             around header => sub {
32             my ($orig, $self) = @_;
33             my $orig_message = $self->$orig;
34             sprintf "%s with HTTP status %d", $orig_message, $self->status;
35             };
36              
37             1;