|
Lines 23-28
use Koha::Database;
Link Here
|
| 23 |
use Koha::Exceptions; |
23 |
use Koha::Exceptions; |
| 24 |
use Koha::Patrons; |
24 |
use Koha::Patrons; |
| 25 |
|
25 |
|
|
|
26 |
use List::MoreUtils qw(any); |
| 26 |
use Scalar::Util qw( blessed ); |
27 |
use Scalar::Util qw( blessed ); |
| 27 |
use Try::Tiny qw( catch try ); |
28 |
use Try::Tiny qw( catch try ); |
| 28 |
|
29 |
|
|
Lines 340-364
sub delete {
Link Here
|
| 340 |
Koha::Exceptions::Exception->throw('Koha::Patron->safe_to_delete returned false but carried no error message'); |
341 |
Koha::Exceptions::Exception->throw('Koha::Patron->safe_to_delete returned false but carried no error message'); |
| 341 |
} |
342 |
} |
| 342 |
|
343 |
|
| 343 |
if ( $error->message eq 'has_checkouts' ) { |
344 |
my $error_descriptions = { |
| 344 |
return $c->render( |
345 |
has_checkouts => 'Pending checkouts prevent deletion', |
| 345 |
status => 409, |
346 |
has_debt => 'Pending debts prevent deletion', |
| 346 |
openapi => { error => 'Pending checkouts prevent deletion' } |
347 |
has_guarantees => 'Patron is a guarantor and it prevents deletion', |
| 347 |
); |
348 |
is_anonymous_patron => 'Anonymous patron cannot be deleted', |
| 348 |
} elsif ( $error->message eq 'has_debt' ) { |
349 |
}; |
| 349 |
return $c->render( |
350 |
|
| 350 |
status => 409, |
351 |
if ( any { $error->message eq $_ } keys %{$error_descriptions} ) { |
| 351 |
openapi => { error => 'Pending debts prevent deletion' } |
|
|
| 352 |
); |
| 353 |
} elsif ( $error->message eq 'has_guarantees' ) { |
| 354 |
return $c->render( |
352 |
return $c->render( |
| 355 |
status => 409, |
353 |
status => 409, |
| 356 |
openapi => { error => 'Patron is a guarantor and it prevents deletion' } |
354 |
openapi => { |
| 357 |
); |
355 |
error => $error_descriptions->{ $error->message }, |
| 358 |
} elsif ( $error->message eq 'is_anonymous_patron' ) { |
356 |
error_code => $error->message, |
| 359 |
return $c->render( |
357 |
} |
| 360 |
status => 403, |
|
|
| 361 |
openapi => { error => 'Anonymous patron cannot be deleted' } |
| 362 |
); |
358 |
); |
| 363 |
} else { |
359 |
} else { |
| 364 |
Koha::Exceptions::Exception->throw( 'Koha::Patron->safe_to_delete carried an unexpected message: ' . $error->message ); |
360 |
Koha::Exceptions::Exception->throw( 'Koha::Patron->safe_to_delete carried an unexpected message: ' . $error->message ); |
|
Lines 377-388
sub delete {
Link Here
|
| 377 |
} |
373 |
} |
| 378 |
); |
374 |
); |
| 379 |
} catch { |
375 |
} catch { |
| 380 |
if ( blessed $_ && $_->isa('Koha::Exceptions::Patron::FailedDeleteAnonymousPatron') ) { |
|
|
| 381 |
return $c->render( |
| 382 |
status => 403, |
| 383 |
openapi => { error => "Anonymous patron cannot be deleted" } |
| 384 |
); |
| 385 |
} |
| 386 |
|
376 |
|
| 387 |
$c->unhandled_exception($_); |
377 |
$c->unhandled_exception($_); |
| 388 |
}; |
378 |
}; |
| 389 |
- |
|
|