line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebAPI::HTTP::Throwable::Factory; |
2
|
|
|
|
|
|
|
$WebAPI::HTTP::Throwable::Factory::VERSION = '0.004001'; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# I'm not sure what value there is here, but maybe I'm just forgetting the goodness. |
5
|
|
|
|
|
|
|
# Exception handling probably needs to be rethought. |
6
|
|
|
|
|
|
|
# See also WebAPI::HTTP::Throwable::Role::JSONBody |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
13908828
|
use strict; |
|
2
|
|
|
|
|
20
|
|
|
2
|
|
|
|
|
170
|
|
9
|
2
|
|
|
2
|
|
23
|
use warnings; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
209
|
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
1131
|
use parent 'HTTP::Throwable::Factory'; |
|
2
|
|
|
|
|
893
|
|
|
2
|
|
|
|
|
14
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use Carp qw(carp cluck); |
14
|
|
|
|
|
|
|
use JSON::MaybeXS qw(JSON); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub extra_roles { |
18
|
|
|
|
|
|
|
return ( |
19
|
|
|
|
|
|
|
'WebAPI::HTTP::Throwable::Role::JSONBody', # remove HTTP::Throwable::Role::TextBody |
20
|
|
|
|
|
|
|
'StackTrace::Auto' |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub throw_bad_request { |
25
|
|
|
|
|
|
|
my ($class, $status, %opts) = @_; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
cluck("bad status $status") unless $status =~ /^4\d\d$/; |
28
|
|
|
|
|
|
|
carp("throw_bad_request @_") if $ENV{WEBAPI_DBIC_DEBUG}; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# XXX TODO validations |
31
|
|
|
|
|
|
|
my $data = { |
32
|
|
|
|
|
|
|
errors => $opts{errors}, |
33
|
|
|
|
|
|
|
}; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $json_body = JSON->new->ascii->pretty->encode($data); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# [ 'Content-Type' => 'application/hal+json' ], |
38
|
|
|
|
|
|
|
$class->throw( BadRequest => { |
39
|
|
|
|
|
|
|
status_code => $status, |
40
|
|
|
|
|
|
|
message => $json_body, |
41
|
|
|
|
|
|
|
}); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
return; # not reached |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
__END__ |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=pod |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=encoding UTF-8 |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 NAME |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
WebAPI::HTTP::Throwable::Factory |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 VERSION |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
version 0.004001 |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 DESCRIPTION |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Throw L<HTTP::Throwable> exceptions that contain JSON in the body. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
See also L<WebAPI::HTTP::Throwable::Role::JSONBody>. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 NAME |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
WebAPI::HTTP::Throwable::Factory - methods to support throwing HTTP exceptions |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 AUTHOR |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Tim Bunce <Tim.Bunce@pobox.com> |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Tim Bunce. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
83
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |