diff options
author | franck cuny <franck@lumberjaph.net> | 2010-01-11 10:52:13 +0100 |
---|---|---|
committer | franck cuny <franck@lumberjaph.net> | 2010-01-11 10:52:13 +0100 |
commit | e6940b213c5e00fb938978a56e862bf1e957da60 (patch) | |
tree | 309fc19a1c16a686e4b03665edf17eb343e83107 | |
parent | Checking in changes prior to tagging of version 0.09. Changelog diff is: (diff) | |
download | moosex-net-api-e6940b213c5e00fb938978a56e862bf1e957da60.tar.gz |
stringify error
-rw-r--r-- | lib/MooseX/Net/API.pm | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/MooseX/Net/API.pm b/lib/MooseX/Net/API.pm index 937c150..f0a03aa 100644 --- a/lib/MooseX/Net/API.pm +++ b/lib/MooseX/Net/API.pm @@ -70,7 +70,8 @@ sub net_api_declare { } if ( !$options{format_mode} ) { - die MooseX::Net::API::Error->new( reason => "format_mode is not set" ); + die MooseX::Net::API::Error->new( + reason => "format_mode is not set" ); } elsif ( $options{format_mode} !~ /^(?:append|content\-type)$/ ) { die MooseX::Net::API::Error->new( @@ -317,13 +318,14 @@ sub _request { $req->content($content); } else { - die MooseX::Net::API::Error->new( reason => "$method is not defined" ); + die MooseX::Net::API::Error->new( + reason => "$method is not defined" ); } $req->header( 'Content-Type' => $list_content_type->{$format} ) if $self->api_format_mode eq 'content-type'; - if ($do_auth || $options->{authentication}) { + if ( $do_auth || $options->{authentication} ) { if ($auth_method) { $req = $self->$auth_method($req); } @@ -346,14 +348,24 @@ sub _do_authentication { package MooseX::Net::API::Error; use Moose; +use JSON::XS; +use Moose::Util::TypeConstraints; use overload '""' => \&error; +subtype error => as 'Str'; +coerce error => from 'HashRef' => via { encode_json $_}; + has http_error => ( is => 'ro', isa => 'HTTP::Response', handles => { http_message => 'message', http_code => 'code' } ); -has reason => ( is => 'ro', isa => 'Str|HashRef', predicate => 'has_reason' ); +has reason => ( + is => 'ro', + isa => 'error', + predicate => 'has_reason', + coerce => 1 +); sub error { my $self = shift; |