| 1 | package WebAPI::HTTP::Throwable::Factory; | ||||||||||
| 2 | 25 | $WebAPI::HTTP::Throwable::Factory::VERSION = '0.004002'; | |||||||||
| 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 | 25 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 25 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 25 | ▶ | use parent 'HTTP::Throwable::Factory'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 25 | ▶ | use Carp qw(carp cluck); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 25 | ▶ | use JSON::MaybeXS qw(JSON); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | 9 | ▶ | sub extra_roles { | ||||||||
|
Subroutine
extra_roles: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 18 | return ( | ||||||||||
| 19 | 9 | 'WebAPI::HTTP::Throwable::Role::JSONBody', # remove HTTP::Throwable::Role::TextBody | |||||||||
| 20 | 'StackTrace::Auto' | ||||||||||
| 21 | ); | ||||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | 9 | ▶ | sub throw_bad_request { | ||||||||
|
Subroutine
throw_bad_request: called CC=3 SCAR=11.6
Pod
undocumented
| |||||||||||
| 25 | 9 | my ($class, $status, %opts) = @_; | |||||||||
| 26 | |||||||||||
| 27 | 9 | ▶ | cluck("bad status $status") unless $status =~ /^4\d\d$/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | 9 | ▶ | carp("throw_bad_request @_") if $ENV{WEBAPI_DBIC_DEBUG}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | |||||||||||
| 30 | # XXX TODO validations | ||||||||||
| 31 | my $data = { | ||||||||||
| 32 | errors => $opts{errors}, | ||||||||||
| 33 | 9 | }; | |||||||||
| 34 | |||||||||||
| 35 | 9 | my $json_body = JSON->new->ascii->pretty->encode($data); | |||||||||
| 36 | |||||||||||
| 37 | # [ 'Content-Type' => 'application/hal+json' ], | ||||||||||
| 38 | 9 | $class->throw( BadRequest => { | |||||||||
| 39 | status_code => $status, | ||||||||||
| 40 | message => $json_body, | ||||||||||
| 41 | }); | ||||||||||
| 42 | |||||||||||
| 43 | 0 | return; # not reached | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | |||||||||||
| 47 | |||||||||||
| 48 | 25 | 1; | |||||||||
| 49 | |||||||||||
| 50 | __END__ | ||||||||||