line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dancer2::RPCPlugin::ErrorResponse; |
2
|
15
|
|
|
15
|
|
214143
|
use Moo; |
|
15
|
|
|
|
|
31742
|
|
|
15
|
|
|
|
|
78
|
|
3
|
|
|
|
|
|
|
|
4
|
15
|
|
|
15
|
|
7691
|
use Exporter 'import'; |
|
15
|
|
|
|
|
33
|
|
|
15
|
|
|
|
|
3100
|
|
5
|
|
|
|
|
|
|
our @EXPORT = qw/error_response/; |
6
|
4
|
|
|
4
|
1
|
738
|
sub error_response { __PACKAGE__->new(@_) } |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has error_code => ( |
9
|
|
|
|
|
|
|
is => 'ro', |
10
|
|
|
|
|
|
|
required => 1 |
11
|
|
|
|
|
|
|
); |
12
|
|
|
|
|
|
|
has error_message => ( |
13
|
|
|
|
|
|
|
is => 'ro', |
14
|
|
|
|
|
|
|
required => 1 |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
has error_data => ( |
17
|
|
|
|
|
|
|
is => 'ro', |
18
|
|
|
|
|
|
|
required => 0 |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub as_xmlrpc_fault { |
22
|
2
|
|
|
2
|
1
|
3628
|
my $self = shift; |
23
|
|
|
|
|
|
|
return { |
24
|
2
|
|
|
|
|
17
|
faultCode => $self->error_code, |
25
|
|
|
|
|
|
|
faultString => $self->error_message, |
26
|
|
|
|
|
|
|
}; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub as_jsonrpc_error { |
30
|
3
|
|
|
3
|
1
|
7
|
my $self = shift; |
31
|
|
|
|
|
|
|
|
32
|
3
|
|
|
|
|
9
|
my $data = $self->error_data; |
33
|
|
|
|
|
|
|
return { |
34
|
3
|
100
|
|
|
|
33
|
error => { |
35
|
|
|
|
|
|
|
code => $self->error_code, |
36
|
|
|
|
|
|
|
message => $self->error_message, |
37
|
|
|
|
|
|
|
($data ? (data => $data) : ()), |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub as_restrpc_error { |
43
|
6
|
|
|
6
|
1
|
2960
|
my $self = shift; |
44
|
|
|
|
|
|
|
|
45
|
6
|
|
|
|
|
20
|
my $data = $self->error_data; |
46
|
|
|
|
|
|
|
return { |
47
|
6
|
100
|
|
|
|
66
|
error => { |
48
|
|
|
|
|
|
|
code => $self->error_code, |
49
|
|
|
|
|
|
|
message => $self->error_message, |
50
|
|
|
|
|
|
|
($data ? (data => $data) : ()), |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
}; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 NAME |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Dancer2::RPCPlugin::ErrorResponse - Interface to pass error-responses without knowlage of the protocol |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 SYNOPSIS |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
use Dancer2::RPCPlugin::ErrorResponse; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub handle_rpc_call { |
67
|
|
|
|
|
|
|
... |
68
|
|
|
|
|
|
|
return error_response( |
69
|
|
|
|
|
|
|
error_code => 42, |
70
|
|
|
|
|
|
|
error_message => 'That went belly-up', |
71
|
|
|
|
|
|
|
); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 DESCRIPTION |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 error_response(%parameters) |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Factory function that retuns an instantiated L<Dancer2::RPCPlugin::ErrorResponse>. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head3 Parameters |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=over |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=item error_code => $error_code [required] |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item error_message => $error_message [required] |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=item error_data => $error_data [optional] |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=back |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head3 Responses |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
An instance or an exception from L<Moo>. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 Dancer2::RPCPlugin::ErrorResponse->new(%parameters) |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head3 Parameters |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=over |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item error_code => $error_code [required] |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item error_message => $error_message [required] |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item error_data => $error_data [optional] |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=back |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head3 Responses |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
An instance or an exception from L<Moo>. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 $er->error_code |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Getter for the C<error_code> attribute. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 $er->error_message |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Getter for the C<error_message> attribute. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 $er->error_data |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Getter for the C<error_data> attribute. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 $er->as_jsonrpc_error |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Returns a data-structure for the use in the C<error> field of a jsonrpc response. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 $er->as_xmlrpc_fault |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Returns a data-structure for the use as a C<fault> response in XMLRPC. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 $er->as_restrpc_error |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Returns a data-structure like the C<error-field> in a JSONRPC2 error response. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 COPYRIGHT |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
(c) MMXVII - Abe Timmerman <abetim@cpan.org> |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=cut |