line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OpenAI::API::Error; |
2
|
|
|
|
|
|
|
|
3
|
18
|
|
|
18
|
|
135
|
use Moo; |
|
18
|
|
|
|
|
71
|
|
|
18
|
|
|
|
|
106
|
|
4
|
18
|
|
|
18
|
|
6118
|
use strictures 2; |
|
18
|
|
|
|
|
122
|
|
|
18
|
|
|
|
|
840
|
|
5
|
18
|
|
|
18
|
|
3117
|
use namespace::clean; |
|
18
|
|
|
|
|
46
|
|
|
18
|
|
|
|
|
135
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
extends 'Throwable::Error'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has request => ( |
10
|
|
|
|
|
|
|
is => 'ro', |
11
|
|
|
|
|
|
|
isa => sub { ref $_[0] eq 'HTTP::Request' or die "expected HTTP::Request object" }, |
12
|
|
|
|
|
|
|
); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has response => ( |
15
|
|
|
|
|
|
|
is => 'ro', |
16
|
|
|
|
|
|
|
isa => sub { ref $_[0] eq 'HTTP::Response' or die "expected HTTP::Response object" }, |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
1; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
__END__ |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 NAME |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
OpenAI::API::Error - throwable error objects |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 SYNOPSIS |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
use OpenAI::API::Error; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
OpenAI::API::Error->throw( |
32
|
|
|
|
|
|
|
message => 'Something went wrong', |
33
|
|
|
|
|
|
|
request => $req, |
34
|
|
|
|
|
|
|
response => $res, |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# elsewhere... |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
try { |
40
|
|
|
|
|
|
|
my $response = $openai->$method(...); |
41
|
|
|
|
|
|
|
} catch ($e) { |
42
|
|
|
|
|
|
|
# Handle error |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 DESCRIPTION |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
The C<OpenAI::API::Error> module provides an object-oriented exception |
48
|
|
|
|
|
|
|
mechanism for errors encountered while interacting with the OpenAI |
49
|
|
|
|
|
|
|
API. It extends the L<Throwable::Error> class to include the optional |
50
|
|
|
|
|
|
|
L<HTTP::Request> and L<HTTP::Response> objects, allowing for better |
51
|
|
|
|
|
|
|
error reporting and debugging. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 request |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
The C<request> attribute holds the L<HTTP::Request> object associated |
58
|
|
|
|
|
|
|
with the error. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 response |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
The C<response> attribute holds the L<HTTP::Response> object associated |
63
|
|
|
|
|
|
|
with the error. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 METHODS |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head2 throw |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
The C<throw> method creates a new OpenAI::API::Error object with the |
70
|
|
|
|
|
|
|
provided message, request, and response attributes and throws it as |
71
|
|
|
|
|
|
|
an exception. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 SEE ALSO |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=over 4 |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item * |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
L<Throwable::Error> |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=item * |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
L<HTTP::Request> |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item * |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
L<HTTP::Response> |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=back |