| 1 | package GeoIP2::Error::WebService; | ||
| 2 | |||
| 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 | our $VERSION = '2.006000'; | |
| 7 | |||
| 8 | 1 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 1 | ▶ | use GeoIP2::Types qw( Str ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | 1 | ▶ | use namespace::clean -except => 'meta'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | |||
| 14 | 1 | with 'GeoIP2::Role::Error::HTTP'; | |
| 15 | |||
| 16 | 1 | extends 'Throwable::Error'; | |
| 17 | |||
| 18 | 1 | has code => ( | |
| 19 | is => 'ro', | ||
| 20 | isa => Str, | ||
| 21 | required => 1, | ||
| 22 | ); | ||
| 23 | |||
| 24 | 1 | 1; | |
| 25 | |||
| 26 | # ABSTRACT: An explicit error from the GeoIP2 web service | ||
| 27 | |||
| 28 | __END__ | ||
| 29 | |||
| 30 | =pod | ||
| 31 | |||
| 32 | =encoding UTF-8 | ||
| 33 | |||
| 34 | =head1 NAME | ||
| 35 | |||
| 36 | GeoIP2::Error::WebService - An explicit error from the GeoIP2 web service | ||
| 37 | |||
| 38 | =head1 VERSION | ||
| 39 | |||
| 40 | version 2.006000 | ||
| 41 | |||
| 42 | =head1 SYNOPSIS | ||
| 43 | |||
| 44 | use 5.008; | ||
| 45 | |||
| 46 | use GeoIP2::WebService::Client; | ||
| 47 | use Scalar::Util qw( blessed ); | ||
| 48 | use Try::Tiny; | ||
| 49 | |||
| 50 | my $client = GeoIP2::WebService::Client->new( | ||
| 51 | account_id => 42, | ||
| 52 | license_key => 'abcdef123456', | ||
| 53 | ); | ||
| 54 | |||
| 55 | try { | ||
| 56 | $client->insights( ip => '24.24.24.24' ); | ||
| 57 | } | ||
| 58 | catch { | ||
| 59 | die $_ unless blessed $_; | ||
| 60 | if ( $_->isa('GeoIP2::Error::HTTP') ) { | ||
| 61 | log_web_service_error( | ||
| 62 | maxmind_code => $_->code(), | ||
| 63 | status => $_->http_status(), | ||
| 64 | uri => $_->uri(), | ||
| 65 | ); | ||
| 66 | } | ||
| 67 | |||
| 68 | # handle other exceptions | ||
| 69 | }; | ||
| 70 | |||
| 71 | =head1 DESCRIPTION | ||
| 72 | |||
| 73 | This class represents an error returned by MaxMind's GeoIP2 web service. It | ||
| 74 | extends L<Throwable::Error> and adds attributes of its own. | ||
| 75 | |||
| 76 | =head1 METHODS | ||
| 77 | |||
| 78 | The C<< $error->message() >>, and C<< $error->stack_trace() >> methods are | ||
| 79 | inherited from L<Throwable::Error>. The message will be the value provided by | ||
| 80 | the MaxMind web service. See L<http://dev.maxmind.com/geoip/geoip2/web-services> for | ||
| 81 | details. | ||
| 82 | |||
| 83 | It also provides three methods of its own: | ||
| 84 | |||
| 85 | =head2 $error->code() | ||
| 86 | |||
| 87 | Returns the code returned by the MaxMind GeoIP2 web service. | ||
| 88 | |||
| 89 | =head2 $error->http_status() | ||
| 90 | |||
| 91 | Returns the HTTP status. This should be either a 4xx or 5xx error. | ||
| 92 | |||
| 93 | =head2 $error->uri() | ||
| 94 | |||
| 95 | Returns the URI which gave the HTTP error. | ||
| 96 | |||
| 97 | =head1 SUPPORT | ||
| 98 | |||
| 99 | =head1 AUTHORS | ||
| 100 | |||
| 101 | =over 4 | ||
| 102 | |||
| 103 | =item * | ||
| 104 | |||
| 105 | Dave Rolsky <drolsky@maxmind.com> | ||
| 106 | |||
| 107 | =item * | ||
| 108 | |||
| 109 | Greg Oschwald <goschwald@maxmind.com> | ||
| 110 | |||
| 111 | =item * | ||
| 112 | |||
| 113 | Mark Fowler <mfowler@maxmind.com> | ||
| 114 | |||
| 115 | =item * | ||
| 116 | |||
| 117 | Olaf Alders <oalders@maxmind.com> | ||
| 118 | |||
| 119 | =back | ||
| 120 | |||
| 121 | =head1 COPYRIGHT AND LICENSE | ||
| 122 | |||
| 123 | This software is copyright (c) 2013 - 2018 by MaxMind, Inc. | ||
| 124 | |||
| 125 | This is free software; you can redistribute it and/or modify it under | ||
| 126 | the same terms as the Perl 5 programming language system itself. | ||
| 127 | |||
| 128 | =cut | ||