line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CatalystX::Eta::Controller::REST; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
5314213
|
use Moose; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
13
|
|
4
|
2
|
|
|
2
|
|
11264
|
use namespace::autoclean; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
23
|
|
5
|
2
|
|
|
2
|
|
150
|
use Data::Dumper; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
116
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
11
|
use JSON::MaybeXS; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
138
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
7
|
BEGIN { extends 'Catalyst::Controller::REST' } |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
__PACKAGE__->config( |
12
|
|
|
|
|
|
|
default => 'application/json', |
13
|
|
|
|
|
|
|
'map' => { |
14
|
|
|
|
|
|
|
'application/json' => 'JSON', |
15
|
|
|
|
|
|
|
'text/x-json' => 'JSON', |
16
|
|
|
|
|
|
|
}, |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub end : Private { |
20
|
14
|
|
|
14
|
1
|
634245
|
my ( $self, $c ) = @_; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
#... do things before Serializing ... |
23
|
14
|
|
|
|
|
73
|
my $code = $c->res->status; |
24
|
14
|
50
|
|
|
|
1820
|
if ( scalar( @{ $c->error } ) ) { |
|
14
|
|
|
|
|
51
|
|
25
|
0
|
|
|
|
|
0
|
$code = 500; # We default to 500 for errors unless something else has been set. |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
0
|
my ( $an_error, @other_errors ) = @{ $c->error }; |
|
0
|
|
|
|
|
0
|
|
28
|
|
|
|
|
|
|
|
29
|
0
|
0
|
0
|
|
|
0
|
if ( ref $an_error eq 'DBIx::Class::Exception' |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
30
|
|
|
|
|
|
|
&& $an_error->{msg} =~ /duplicate key value violates unique constraint/ ) { |
31
|
0
|
|
|
|
|
0
|
$code = 400; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$c->stash->{rest} = |
34
|
0
|
|
|
|
|
0
|
{ error => 'You violated an unique constraint! Please verify your input fields and try again.' }; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
0
|
$c->log->info( "exception treated: " . $an_error->{msg} ); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
elsif ( ref $an_error eq 'DBIx::Class::Exception' |
39
|
|
|
|
|
|
|
&& $an_error->{msg} =~ /is not present/ ) { |
40
|
0
|
|
|
|
|
0
|
$code = 400; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
0
|
my ( $match, $value ) = $an_error->{msg} =~ /Key \((.+?)\)=(\(.+?)\)/; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$c->stash->{rest} = |
45
|
0
|
|
|
|
|
0
|
{ form_error => ( { $match => 'value=' . $value . ') cannot be found on our database' } ) }; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
elsif ( ref $an_error eq 'HASH' && $an_error->{error_code} ) { |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
0
|
$code = $an_error->{error_code}; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$c->stash->{rest} = |
53
|
0
|
|
|
|
|
0
|
{ error => $an_error->{message} }; |
54
|
0
|
|
|
|
|
0
|
$c->log->info( "exception treated: " . $an_error->{msg} ); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
elsif ( ref $an_error eq 'REF' && ref $$an_error eq 'ARRAY' && @$$an_error == 2 ) { |
58
|
0
|
|
|
|
|
0
|
$code = 400; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
$c->stash->{rest} = |
61
|
0
|
|
|
|
|
0
|
{ form_error => ( { $$an_error->[0] => $$an_error->[1] } ) }; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
else { |
65
|
0
|
|
|
|
|
0
|
$c->log->error( Dumper $an_error, @other_errors ); |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
0
|
$c->stash->{rest} = { error => 'Internal Server Error' }; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
0
|
$c->clear_errors; |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
0
|
$c->res->status($code); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
$c->stash->{rest}{error} = 'form_error' |
76
|
|
|
|
|
|
|
if ref $c->stash->{rest} eq 'HASH' |
77
|
|
|
|
|
|
|
&& !exists $c->stash->{rest}{error} |
78
|
14
|
50
|
100
|
|
|
164
|
&& exists $c->stash->{rest}{form_error}; |
|
|
|
66
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
14
|
|
|
|
|
2404
|
$c->forward('serialize'); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
#... do things after Serializing ... |
83
|
2
|
|
|
2
|
|
12205
|
} |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
25
|
|
84
|
|
|
|
|
|
|
|
85
|
2
|
|
|
2
|
0
|
2313
|
sub serialize : ActionClass('Serialize') { } |
|
2
|
|
|
14
|
|
4
|
|
|
2
|
|
|
|
|
10
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
|