File Coverage

blib/lib/WebService/MinFraud/Error/WebService.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             package WebService::MinFraud::Error::WebService;
2              
3 1     1   6 use Moo;
  1         2  
  1         5  
4 1     1   249 use namespace::autoclean;
  1         1  
  1         8  
5              
6             our $VERSION = '1.010000';
7              
8 1     1   90 use WebService::MinFraud::Types qw( Str );
  1         2  
  1         73  
9              
10             with 'WebService::MinFraud::Role::Error::HTTP';
11              
12             extends 'Throwable::Error';
13              
14             has code => (
15             is => 'ro',
16             isa => Str,
17             required => 1,
18             );
19              
20             1;
21              
22             # ABSTRACT: An explicit error returned by the minFraud web service
23              
24             __END__
25              
26             =pod
27              
28             =encoding UTF-8
29              
30             =head1 NAME
31              
32             WebService::MinFraud::Error::WebService - An explicit error returned by the minFraud web service
33              
34             =head1 VERSION
35              
36             version 1.010000
37              
38             =head1 SYNOPSIS
39              
40             use 5.010;
41              
42             use WebService::MinFraud::Client;
43              
44             use Scalar::Util qw( blessed );
45             use Try::Tiny;
46              
47             my $client = WebService::MinFraud::Client->new(
48             account_id => 42,
49             license_key => 'abcdef123456',
50             );
51              
52             try {
53             my $request = { device => { ip_address => '24.24.24.24' } };
54             $client->insights($request);
55             }
56             catch {
57             die $_ unless blessed $_;
58             if ( $_->isa('WebService::MinFraud::Error::WebService') ) {
59             log_web_service_error(
60             error_message => $_->message,
61             maxmind_code => $_->code,
62             status => $_->http_status,
63             uri => $_->uri,
64             );
65             }
66              
67             # handle other exceptions
68             };
69              
70             =head1 DESCRIPTION
71              
72             This class represents an error returned by MaxMind's minFraud web service. It
73             extends L<Throwable::Error> and adds attributes of its own.
74              
75             =head1 METHODS
76              
77             The C<< message >> and C<< stack_trace >> methods are
78             inherited from L<Throwable::Error>. The message will be the value provided by
79             the MaxMind web service. See L<https://dev.maxmind.com/minfraud> for
80             details.
81              
82             It also provides three methods of its own:
83              
84             =head2 code
85              
86             Returns the code returned by the MaxMind minFraud web service.
87              
88             =head2 http_status
89              
90             Returns the HTTP status. This should be either a 4xx or 5xx error.
91              
92             =head2 uri
93              
94             Returns the URI which gave the HTTP error.
95              
96             =head1 SUPPORT
97              
98             Bugs may be submitted through L<https://github.com/maxmind/minfraud-api-perl/issues>.
99              
100             =head1 AUTHOR
101              
102             Mateu Hunter <mhunter@maxmind.com>
103              
104             =head1 COPYRIGHT AND LICENSE
105              
106             This software is copyright (c) 2015 - 2020 by MaxMind, Inc.
107              
108             This is free software; you can redistribute it and/or modify it under
109             the same terms as the Perl 5 programming language system itself.
110              
111             =cut