diff options
| author | franck cuny <franck@lumberjaph.net> | 2010-07-16 16:10:41 +0200 |
|---|---|---|
| committer | franck cuny <franck@lumberjaph.net> | 2010-07-16 16:10:41 +0200 |
| commit | e97449eaa8bd3a408763057f9ca2253d93e2a3d0 (patch) | |
| tree | 4fd0dc6ed899efe361e314adfc913b9aa6b0a1a4 /lib/Net/HTTP/API/Error.pm | |
| parent | check if auth_method is declared (diff) | |
| download | net-http-api-e97449eaa8bd3a408763057f9ca2253d93e2a3d0.tar.gz | |
rename from mx::net::api to net::http::api
Diffstat (limited to 'lib/Net/HTTP/API/Error.pm')
| -rw-r--r-- | lib/Net/HTTP/API/Error.pm | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/Net/HTTP/API/Error.pm b/lib/Net/HTTP/API/Error.pm new file mode 100644 index 0000000..43157b5 --- /dev/null +++ b/lib/Net/HTTP/API/Error.pm @@ -0,0 +1,43 @@ +package Net::HTTP::API::Error; + +# ABSTRACT: Throw error + +use Moose; +use JSON; +use Moose::Util::TypeConstraints; +use overload '""' => \&error; + +subtype error => as 'Str'; +coerce error => from 'HashRef' => via { JSON::encode_json $_}; + +has http_error => ( + is => 'ro', + isa => 'HTTP::Response', + handles => { http_message => 'message', http_code => 'code' } +); +has reason => ( + is => 'ro', + isa => 'error', + predicate => 'has_reason', + coerce => 1 +); + +sub error { + my $self = shift; + return + ( $self->has_reason && $self->reason ) + || ( $self->http_message . ": " . $self->http_code ) + || 'unknown'; +} + +1; + +=head1 SYNOPSIS + + Net::HTTP::API::Error->new(reason => "'useragent' is required"); + +or + + Net::HTTP::API::Error->new() + +=head1 DESCRIPTION |
