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