Bug 29496: CheckMandatorySubfields don't work properly with select field in serials...
[koha-ffzg.git] / svc / renew
index e7792dd..91f7958 100755 (executable)
--- a/svc/renew
+++ b/svc/renew
@@ -21,8 +21,9 @@ use Modern::Perl;
 
 use CGI;
 use JSON qw(to_json);
+use Try::Tiny;
 
-use C4::Circulation;
+use C4::Circulation qw( AddRenewal CanBookBeRenewed );
 use C4::Context;
 use C4::Auth qw(check_cookie_auth);
 
@@ -30,7 +31,7 @@ use Koha::DateUtils qw(output_pref dt_from_string);
 
 my $input = CGI->new;
 
-my ( $auth_status, $sessionID ) =
+my ( $auth_status ) =
   check_cookie_auth( $input->cookie('CGISESSID'),
     { circulate => 'circulate_remaining_permissions' } );
 
@@ -67,8 +68,16 @@ if ( $data->{error} && $data->{error} eq 'on_reserve' && C4::Context->preference
 }
 
 if ( $data->{renew_okay} ) {
-    $date_due = AddRenewal( $borrowernumber, $itemnumber, $branchcode, $date_due, undef, undef, $seen );
-    $data->{date_due} = output_pref( { dt => $date_due, as_due_date => 1 } );
+    try{
+        $date_due = AddRenewal( $borrowernumber, $itemnumber, $branchcode, $date_due, undef, undef, $seen );
+        $data->{date_due} = output_pref( { dt => $date_due, as_due_date => 1 } );
+    } catch {
+        if ( ref($_) eq 'Koha::Exceptions::Checkout::FailedRenewal' ) {
+            $data->{error} = 'renewal_failed';
+        } else {
+            $_->rethrow;
+        }
+    };
 }
 
 print to_json($data);