File Coverage

blib/lib/RT/Client/REST/Exception.pm
Criterion Covered Total %
statement 18 46 39.1
branch 0 22 0.0
condition 0 3 0.0
subroutine 6 8 75.0
pod n/a
total 24 79 30.3


line stmt bran cond sub pod time code
1             #!perl
2             # PODNAME: RT::Client::REST::Exception
3             # ABSTRACT: Exceptions thrown by RT::Client::REST
4              
5 24     24   3300 use strict;
  24         47  
  24         693  
6 24     24   116 use warnings;
  24         42  
  24         1024  
7              
8             $RT::Client::REST::Exception::VERSION = '0.70';
9             use parent qw(Exception::Class);
10 24     24   141  
  24         44  
  24         191  
11             use vars qw($VERSION);
12 24     24   212759 $VERSION = '0.19';
  24         56  
  24         4514  
13              
14             use Exception::Class (
15             'RT::Client::REST::OddNumberOfArgumentsException' => {
16 24         709 isa => __PACKAGE__,
17             description => 'This means that we wanted name/value pairs',
18             },
19              
20             'RT::Client::REST::InvaildObjectTypeException' => {
21             isa => __PACKAGE__,
22             description => 'Invalid object type was specified',
23             },
24              
25             'RT::Client::REST::MalformedRTResponseException' => {
26             isa => __PACKAGE__,
27             description => 'Malformed RT response received from server',
28             },
29              
30             'RT::Client::REST::InvalidParameterValueException' => {
31             isa => __PACKAGE__,
32             description => 'This happens when you feed me bad values',
33             },
34              
35             'RT::Client::REST::CannotReadAttachmentException' => {
36             isa => __PACKAGE__,
37             description => 'Cannot read attachment',
38             },
39              
40             'RT::Client::REST::RequiredAttributeUnsetException' => {
41             isa => __PACKAGE__,
42             description => 'An operation failed because a required attribute ' .
43             'was not set in the object',
44             },
45              
46              
47             'RT::Client::REST::RTException' => {
48             isa => __PACKAGE__,
49             fields => ['code'],
50             description => 'RT server returned an error code',
51             },
52              
53             'RT::Client::REST::ObjectNotFoundException' => {
54             isa => 'RT::Client::REST::RTException',
55             description => 'One or more of the specified objects was not found',
56             },
57              
58             'RT::Client::REST::CouldNotCreateObjectException' => {
59             isa => 'RT::Client::REST::RTException',
60             description => 'Object could not be created',
61             },
62              
63             'RT::Client::REST::AuthenticationFailureException' => {
64             isa => 'RT::Client::REST::RTException',
65             description => 'Incorrect username or password',
66             },
67              
68             'RT::Client::REST::UpdateException' => {
69             isa => 'RT::Client::REST::RTException',
70             description => 'Error updating an object. Virtual exception',
71             },
72              
73             'RT::Client::REST::UnknownCustomFieldException' => {
74             isa => 'RT::Client::REST::RTException',
75             description => 'Unknown custom field',
76             },
77              
78             'RT::Client::REST::InvalidQueryException' => {
79             isa => 'RT::Client::REST::RTException',
80             description => 'Invalid query (server could not parse it)',
81             },
82              
83             'RT::Client::REST::CouldNotSetAttributeException' => {
84             isa => 'RT::Client::REST::UpdateException',
85             description => 'Attribute could not be updated with a new value',
86             },
87              
88             'RT::Client::REST::InvalidEmailAddressException' => {
89             isa => 'RT::Client::REST::UpdateException',
90             description => 'Invalid e-mail address',
91             },
92              
93             'RT::Client::REST::AlreadyCurrentValueException' => {
94             isa => 'RT::Client::REST::UpdateException',
95             description => 'The attribute you are trying to update already has '.
96             'this value',
97             },
98              
99             'RT::Client::REST::ImmutableFieldException' => {
100             isa => 'RT::Client::REST::UpdateException',
101             description => 'Trying to update an immutable field',
102             },
103              
104             'RT::Client::REST::IllegalValueException' => {
105             isa => 'RT::Client::REST::UpdateException',
106             description => 'Illegal value',
107             },
108              
109             'RT::Client::REST::UnauthorizedActionException' => {
110             isa => 'RT::Client::REST::RTException',
111             description => 'You are not authorized to perform this action',
112             },
113              
114             'RT::Client::REST::AlreadyTicketOwnerException' => {
115             isa => 'RT::Client::REST::RTException',
116             description => 'The owner you are trying to assign to a ticket ' .
117             'is already the owner',
118             },
119              
120             'RT::Client::REST::RequestTimedOutException' => {
121             isa => 'RT::Client::REST::RTException',
122             description => 'Request timed out',
123             },
124              
125             'RT::Client::REST::UnknownRTException' => {
126             isa => 'RT::Client::REST::RTException',
127             description => 'Some other RT error',
128             },
129              
130             'RT::Client::REST::HTTPException' => {
131             isa => __PACKAGE__,
132             fields => ['code'],
133             description => 'Error in the underlying protocol (HTTP)',
134             },
135             );
136 24     24   149  
  24         52  
137             my ($self, $content) = @_;
138              
139 0     0     if ($content =~ m/not found|\d+ does not exist|[Ii]nvalid attachment id/) {
140             return 'RT::Client::REST::ObjectNotFoundException';
141 0 0         }
142 0           if ($content =~ m/not create/) {
143             return 'RT::Client::REST::CouldNotCreateObjectException';
144 0 0         }
145 0           if ($content =~ m/[Uu]nknown custom field/) {
146             return 'RT::Client::REST::UnknownCustomFieldException';
147 0 0         }
148 0           if ($content =~ m/[Ii]nvalid query/) {
149             return 'RT::Client::REST::InvalidQueryException';
150 0 0         }
151 0           if ($content =~ m/could not be set to/) {
152             return 'RT::Client::REST::CouldNotSetAttributeException';
153 0 0         }
154 0           if ($content =~ m/not a valid email address/) {
155             return 'RT::Client::REST::InvalidEmailAddressException';
156 0 0         }
157 0           if ($content =~ m/is already the current value/) {
158             return 'RT::Client::REST::AlreadyCurrentValueException';
159 0 0         }
160 0           if ($content =~ m/[Ii]mmutable field/) {
161             return 'RT::Client::REST::ImmutableFieldException';
162 0 0         }
163 0           if ($content =~ m/[Ii]llegal value/) {
164             return 'RT::Client::REST::IllegalValueException';
165 0 0         }
166 0           if ($content =~ m/[Yy]ou are not allowed/) {
167             return 'RT::Client::REST::UnauthorizedActionException';
168 0 0         }
169 0           if ($content =~ m/[Yy]ou already own this ticket/ ||
170             $content =~ m/[Tt]hat user already owns that ticket/)
171 0 0 0       {
172             return 'RT::Client::REST::AlreadyTicketOwnerException';
173             }
174 0            
175             return 'RT::Client::REST::UnknownRTException';
176             }
177 0            
178             my ($self, $content) = @_;
179              
180             (my $message = $content) =~ s/^#\s*//;
181 0     0     chomp($message);
182              
183 0           return $self->_get_exception_class($content)->new(
184 0           message => $message,
185             );
186 0           }
187              
188             # Some mildly weird magic to fix up inheritance (see Exception::Class POD).
189             {
190             no strict 'refs'; ## no critic (ProhibitNoStrict)
191             push @{__PACKAGE__ . '::ISA'}, 'Exception::Class::Base';
192             }
193 24     24   135426  
  24         65  
  24         2260  
194              
195             1;
196              
197             =pod
198              
199             =encoding UTF-8
200              
201             =head1 NAME
202              
203             RT::Client::REST::Exception - Exceptions thrown by RT::Client::REST
204              
205             =head1 VERSION
206              
207             version 0.70
208              
209             =head1 DESCRIPTION
210              
211             These are exceptions that are thrown by various L<RT::Client::REST>
212             methods.
213              
214             =head1 EXCEPTION HIERARCHY
215              
216             =over 2
217              
218             =item B<RT::Client::REST::Exception>
219              
220             This exception is virtual -- it is never thrown. It is used to group
221             all the exceptions in this category.
222              
223             =over 2
224              
225             =item B<RT::Client::REST::OddNumberOfArgumentsException>
226              
227             This means that the method you called wants key-value pairs.
228              
229             =item B<RT::Client::REST::InvaildObjectTypeException>
230              
231             Thrown when you specify an invalid type to C<show()>, C<edit()>, or
232             C<search()> methods.
233              
234             =item B<RT::Client::REST::RequiredAttributeUnsetException>
235              
236             An operation failed because a required attribute was not set in the object.
237              
238             =item B<RT::Client::REST::MalformedRTResponseException>
239              
240             RT server sent response that we cannot parse. This may very well mean
241             a bug in this client, so if you get this exception, some debug information
242             mailed to the author would be appreciated.
243              
244             =item B<RT::Client::REST::InvalidParameterValueException>
245              
246             Invalid value for comments, link types, object IDs, etc.
247              
248             =item B<RT::Client::REST::CannotReadAttachmentException>
249              
250             Cannot read attachment (thrown from methods "comment()" and "correspond").
251              
252             =item B<RT::Client::REST::RTException>
253              
254             This is a virtual exception and is never thrown. It is used to group
255             exceptions thrown because RT server returns an error.
256              
257             =over 2
258              
259             =item B<RT::Client::REST::ObjectNotFoundException>
260              
261             One or more of the specified objects was not found.
262              
263             =item B<RT::Client::REST::AuthenticationFailureException>
264              
265             Incorrect username or password.
266              
267             =item B<RT::Client::REST::UpdateException>
268              
269             This is a virtual exception. It is used to group exceptions thrown when
270             RT server returns an error trying to update an object.
271              
272             =over 2
273              
274             =item B<RT::Client::REST::CouldNotSetAttributeException>
275              
276             For one or another reason, attribute could not be updated with the new
277             value.
278              
279             =item B<RT::Client::REST::InvalidEmailAddressException>
280              
281             Invalid e-mail address specified.
282              
283             =item B<RT::Client::REST::AlreadyCurrentValueException>
284              
285             The attribute you are trying to update already has this value. I do not
286             know why RT insists on treating this as an exception, but since it does so,
287             so should the client. You can probably safely catch and throw away this
288             exception in your code.
289              
290             =item B<RT::Client::REST::ImmutableFieldException>
291              
292             Trying to update an immutable field (such as "last_updated", for
293             example).
294              
295             =item B<RT::Client::REST::IllegalValueException>
296              
297             Illegal value for attribute was specified.
298              
299             =back
300              
301             =item B<RT::Client::REST::UnknownCustomFieldException>
302              
303             Unknown custom field was specified in the request.
304              
305             =item B<RT::Client::REST::InvalidQueryException>
306              
307             Server could not parse the search query.
308              
309             =item B<RT::Client::REST::UnauthorizedActionException>
310              
311             You are not authorized to perform this action.
312              
313             =item B<RT::Client::REST::AlreadyTicketOwnerException>
314              
315             The owner you are trying to assign to a ticket is already the owner.
316             This exception is usually thrown by methods C<take()>, C<untake>, and
317             C<steal>, if the operation is a noop.
318              
319             =item B<RT::Client::REST::RequestTimedOutException>
320              
321             Request timed out.
322              
323             =item B<RT::Client::REST::UnknownRTException>
324              
325             Some other RT exception that the driver cannot recognize.
326              
327             =back
328              
329             =back
330              
331             =back
332              
333             =head1 METHODS
334              
335             =over 2
336              
337             =item B<_get_exception_class>
338              
339             Figure out exception class based on content returned by RT.
340              
341             =item B<_rt_content_to_exception>
342              
343             Translate error string returned by RT server into an exception object
344             ready to be thrown.
345              
346             =back
347              
348             =head1 SEE ALSO
349              
350             L<Exception::Class>,
351             L<RT::Client::REST>.
352              
353             =head1 AUTHOR
354              
355             Dean Hamstead <dean@fragfest.com.au>
356              
357             =head1 COPYRIGHT AND LICENSE
358              
359             This software is copyright (c) 2022, 2020 by Dmitri Tikhonov.
360              
361             This is free software; you can redistribute it and/or modify it under
362             the same terms as the Perl 5 programming language system itself.
363              
364             =cut
365              
366              
367              
368             RT::Client::REST::Exception -- exceptions thrown by RT::Client::REST
369             methods.