LP#1772680: add some guards
authorGalen Charlton <gmc@equinoxinitiative.org>
Thu, 20 Sep 2018 20:52:27 +0000 (16:52 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Tue, 4 Jun 2019 21:33:17 +0000 (17:33 -0400)
Avoid crashes if the RBDigital API is not available or incorrect
tokens are configured.

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/EbookAPI.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/EbookAPI/RBDigital.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/RBDigitalSearch.pm

index e80e079..061cc0a 100644 (file)
@@ -956,6 +956,7 @@ sub get_patron_id {
     
     $logger->error("EbookAPI: User Authenticated. Now, calling for patron authentication");
     my $handler = new_handler($session_id);
+    return unless defined $handler;
     return $handler->do_patron_auth($editor->requestor->usrname, $editor->requestor->email);
 }
 
index e56a673..5030652 100644 (file)
@@ -204,17 +204,13 @@ sub _get_patron_id {
     };
 
     my $res = $self->request($req, $session_id);
-    if ($res && defined($res->{content}->{patronId})) {
-        $self->{patron_id} = $res->{content}->{patronId};
-        return $res->{content}->{patronId};
-    } 
 
     if (defined ($res)) {
         if ($res->{is_success} && defined($res->{content}->{patronId}) ) {
             $self->{patron_id} = $res->{content}->{patronId};
             return $res->{content}->{patronId};
         } else {
-            $logger->error("EbookAPI: Unable to get patron Id from RBDigital portal: ".$res->{content}->{message});
+            $logger->error("EbookAPI: Unable to get patron Id from RBDigital portal: ".$res->{content});
             return 0;
         }
     } else {
index 9123fe2..b11dab6 100644 (file)
@@ -403,8 +403,8 @@ sub _get_patron_id {
     my $ebook_api = OpenSRF::AppSession->create('open-ils.ebook_api');
     my $api_request = $ebook_api->request('open-ils.ebook_api.get_patron_id', $authtoken, $session_id,0);
 
-    if ($api_request) {
-        return $api_request->recv->content;
+    if (my $resp = $api_request->recv) {
+        return $resp->content;
     }
     
     return 0;