File Coverage

blib/lib/Articulate/Service/Error.pm
Criterion Covered Total %
statement 12 17 70.5
branch n/a
condition 0 4 0.0
subroutine 4 5 80.0
pod 0 1 0.0
total 16 27 59.2


line stmt bran cond sub pod time code
1             package Articulate::Service::Error;
2              
3 6     6   18059 use strict;
  6         11  
  6         194  
4 6     6   28 use warnings;
  6         7  
  6         154  
5              
6             =head1 NAME
7              
8             Articulate::Service::Error
9              
10             =DESCRIPTION
11              
12             Given request data like:
13              
14             {
15             error_type => 'Forbidden',
16             error => {}
17             }
18              
19             Creates an error with those attriutes and throws it. No access control is performed.
20              
21             Useful for when you want to throw an error from your route and serialise it.
22              
23             =cut
24              
25 6     6   340 use Articulate::Syntax;
  6         14  
  6         41  
26              
27 6     6   8144 use Moo;
  6         13  
  6         36  
28             with 'Articulate::Role::Service';
29              
30             sub handle_error {
31 0     0 0   my $self = shift;
32 0           my $request = shift;
33 0   0       my $error_type = $request->data->error_type // 'Internal';
34 0   0       my $error_data = $request->data->error // {};
35 0           throw_error $error_type, $error_data;
36             }
37              
38             1;