From ff1fd6231484ed1d2988f7d3b618c6a50b6a87e7 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Tue, 18 Oct 2022 21:11:36 +0000 Subject: [PATCH] Bug 32030: Handle error 401 Unauthorized from EBSCO api Signed-off-by: Jonathan Field Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- Koha/ERM/Providers/EBSCO.pm | 2 ++ Koha/REST/V1/ERM/EHoldings/Packages/EBSCO.pm | 14 ++++++++++++++ Koha/REST/V1/ERM/EHoldings/Titles/EBSCO.pm | 14 ++++++++++++++ koha-tmpl/intranet-tmpl/prog/js/datatables.js | 6 +++++- 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Koha/ERM/Providers/EBSCO.pm b/Koha/ERM/Providers/EBSCO.pm index fea500c6b0..3c3ccf86db 100644 --- a/Koha/ERM/Providers/EBSCO.pm +++ b/Koha/ERM/Providers/EBSCO.pm @@ -276,6 +276,8 @@ sub request { warn sprintf "ERROR - EBSCO API %s returned %s - %s\n", $url, $response->code, $message; if ( $response->code == 404 ) { Koha::Exceptions::ObjectNotFound->throw($message); + } elsif ( $response->code == 401 ) { + Koha::Exceptions::Authorization::Unauthorized->throw($message); } else { die sprintf "ERROR requesting EBSCO API\n%s\ncode %s: %s\n", $url, $response->code, $message; diff --git a/Koha/REST/V1/ERM/EHoldings/Packages/EBSCO.pm b/Koha/REST/V1/ERM/EHoldings/Packages/EBSCO.pm index 3f3962856f..6c4e7c4ade 100644 --- a/Koha/REST/V1/ERM/EHoldings/Packages/EBSCO.pm +++ b/Koha/REST/V1/ERM/EHoldings/Packages/EBSCO.pm @@ -68,6 +68,20 @@ sub list { return $c->render( status => 200, openapi => \@packages ); } catch { + if ( blessed $_ ) { + if ( $_->isa('Koha::Exceptions::Authorization::Unauthorized') ) { + return $c->render( + status => 401, + openapi => { + errors => [ + { + message => "Check your ERMProviderEbscoApiKey/ERMProviderEbscoCustomerID system preferences." + } + ] + } + ); + } + } $c->unhandled_exception($_); }; } diff --git a/Koha/REST/V1/ERM/EHoldings/Titles/EBSCO.pm b/Koha/REST/V1/ERM/EHoldings/Titles/EBSCO.pm index 1fb79055eb..73132f89f6 100644 --- a/Koha/REST/V1/ERM/EHoldings/Titles/EBSCO.pm +++ b/Koha/REST/V1/ERM/EHoldings/Titles/EBSCO.pm @@ -92,6 +92,20 @@ sub list { return $c->render( status => 200, openapi => \@titles ); } catch { + if ( blessed $_ ) { + if ( $_->isa('Koha::Exceptions::Authorization::Unauthorized') ) { + return $c->render( + status => 401, + openapi => { + errors => [ + { + message => "Check your ERMProviderEbscoApiKey/ERMProviderEbscoCustomerID system preferences." + } + ] + } + ); + } + } $c->unhandled_exception($_); }; } diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index 9c5386a394..080ac3a782 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -493,7 +493,11 @@ function filterDataTable( table, column, term ){ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { if ( settings && settings.jqXHR ) { console.log("Got %s (%s)".format(settings.jqXHR.status, settings.jqXHR.statusText)); - alert(__("Something went wrong when loading the table.\n%s: %s").format(settings.jqXHR.status, settings.jqXHR.statusText)); + alert(__("Something went wrong when loading the table.\n%s: %s. \n%s").format( + settings.jqXHR.status, + settings.jqXHR.statusText, + settings.jqXHR.responseJSON.errors ? settings.jqXHR.responseJSON.errors[0].message : '' + )); } else { alert(__("Something went wrong when loading the table.")); } -- 2.39.2