Bug 37963: Case 1 - Return if sushi_errors even if response code >= 400
This ensures that SUSHI errors, if present, are shown on the UI even if
response->code >= 400.
This means that if, for example, SUSHI provider returns 401 with SUSHI
error like so:
{"Code": 2020, "Severity": "Error", "Message": "API Key Invalid"}
Then, the 'API Key Invalid' will be shown to the user, without having to
check logs.
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
parent
05381ba6b1
commit
5d53bb4bff
|
|
@ -180,8 +180,11 @@ sub harvest_sushi {
|
|||
$ua->agent( 'Koha/' . Koha::version() );
|
||||
my $response = $ua->simple_request($request);
|
||||
|
||||
my $result = decode_json( $response->decoded_content );
|
||||
|
||||
if ( $response->code >= 400 ) {
|
||||
my $result = decode_json( $response->decoded_content );
|
||||
|
||||
return if $self->_sushi_errors($result);
|
||||
|
||||
my $message;
|
||||
if ( ref($result) eq 'ARRAY' ) {
|
||||
|
|
@ -199,7 +202,6 @@ sub harvest_sushi {
|
|||
}
|
||||
}
|
||||
|
||||
#TODO: May want to add a job error message here?
|
||||
warn sprintf "ERROR - SUSHI service %s returned %s - %s\n", $url,
|
||||
$response->code, $message;
|
||||
if ( $response->code == 404 ) {
|
||||
|
|
@ -208,7 +210,6 @@ sub harvest_sushi {
|
|||
Koha::Exceptions::Authorization::Unauthorized->throw($message);
|
||||
} else {
|
||||
|
||||
#TODO: May want to add a job error message here?
|
||||
die sprintf "ERROR requesting SUSHI service\n%s\ncode %s: %s\n",
|
||||
$url, $response->code,
|
||||
$message;
|
||||
|
|
@ -217,12 +218,10 @@ sub harvest_sushi {
|
|||
return;
|
||||
}
|
||||
|
||||
my $decoded_response = decode_json( $response->decoded_content );
|
||||
|
||||
return if $self->_sushi_errors($decoded_response);
|
||||
return if $self->_sushi_errors($result);
|
||||
|
||||
# Parse the SUSHI response
|
||||
my $sushi_counter = Koha::ERM::EUsage::SushiCounter->new( { response => $decoded_response } );
|
||||
my $sushi_counter = Koha::ERM::EUsage::SushiCounter->new( { response => $result } );
|
||||
my $counter_file = $sushi_counter->get_COUNTER_from_SUSHI;
|
||||
|
||||
return if $self->_counter_file_size_too_large($counter_file);
|
||||
|
|
|
|||
Loading…
Reference in New Issue