| 1 | package GeoIP2::Error::HTTP; | ||
| 2 | 1 | $GeoIP2::Error::HTTP::VERSION = '0.050000'; | |
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 1 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 1 | with 'GeoIP2::Role::Error::HTTP'; | |
| 9 | |||
| 10 | 1 | extends 'Throwable::Error'; | |
| 11 | |||
| 12 | 1 | 1; | |
| 13 | |||
| 14 | # ABSTRACT: An HTTP transport error | ||
| 15 | |||
| 16 | __END__ | ||
| 17 | |||
| 18 | =pod | ||
| 19 | |||
| 20 | =head1 NAME | ||
| 21 | |||
| 22 | GeoIP2::Error::HTTP - An HTTP transport error | ||
| 23 | |||
| 24 | =head1 VERSION | ||
| 25 | |||
| 26 | version 0.050000 | ||
| 27 | |||
| 28 | =head1 SYNOPSIS | ||
| 29 | |||
| 30 | use 5.008; | ||
| 31 | |||
| 32 | use GeoIP2::WebService::Client; | ||
| 33 | use Scalar::Util qw( blessed ); | ||
| 34 | use Try::Tiny; | ||
| 35 | |||
| 36 | my $client = GeoIP2::WebService::Client->new( | ||
| 37 | user_id => 42, | ||
| 38 | license_key => 'abcdef123456', | ||
| 39 | ); | ||
| 40 | |||
| 41 | try { | ||
| 42 | $client->insights( ip => '24.24.24.24' ); | ||
| 43 | } | ||
| 44 | catch { | ||
| 45 | die $_ unless blessed $_; | ||
| 46 | if ( $_->isa('GeoIP2::Error::HTTP') ) { | ||
| 47 | log_http_error( | ||
| 48 | status => $_->http_status(), | ||
| 49 | uri => $_->uri(), | ||
| 50 | ); | ||
| 51 | } | ||
| 52 | |||
| 53 | # handle other exceptions | ||
| 54 | }; | ||
| 55 | |||
| 56 | =head1 DESCRIPTION | ||
| 57 | |||
| 58 | This class represents an HTTP transport error. It extends L<Throwable::Error> | ||
| 59 | and adds attributes of its own. | ||
| 60 | |||
| 61 | =head1 METHODS | ||
| 62 | |||
| 63 | The C<< $error->message() >>, and C<< $error->stack_trace() >> methods are | ||
| 64 | inherited from L<Throwable::Error>. It also provide two methods of its own: | ||
| 65 | |||
| 66 | =head2 $error->http_status() | ||
| 67 | |||
| 68 | Returns the HTTP status. This should be either a 4xx or 5xx error. | ||
| 69 | |||
| 70 | =head2 $error->uri() | ||
| 71 | |||
| 72 | Returns the URI which gave the HTTP error. | ||
| 73 | |||
| 74 | =head1 AUTHORS | ||
| 75 | |||
| 76 | =over 4 | ||
| 77 | |||
| 78 | =item * | ||
| 79 | |||
| 80 | Dave Rolsky <drolsky@maxmind.com> | ||
| 81 | |||
| 82 | =item * | ||
| 83 | |||
| 84 | Greg Oschwald <goschwald@maxmind.com> | ||
| 85 | |||
| 86 | =item * | ||
| 87 | |||
| 88 | Olaf Alders <oalders@maxmind.com> | ||
| 89 | |||
| 90 | =back | ||
| 91 | |||
| 92 | =head1 COPYRIGHT AND LICENSE | ||
| 93 | |||
| 94 | This software is copyright (c) 2014 by MaxMind, Inc.. | ||
| 95 | |||
| 96 | This is free software; you can redistribute it and/or modify it under | ||
| 97 | the same terms as the Perl 5 programming language system itself. | ||
| 98 | |||
| 99 | =cut | ||