From 6cf48173c760047aae6928e47f1313993730c4ed Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Mon, 5 May 2025 10:28:43 +0000 Subject: [PATCH] Bug 39823: Identify error messages based on code Even if severity does not exist. Additionally, only add severity to message if it exists. Test plan: 1) Apply tests patches. Run tests (they should fail): prove t/db_dependent/Koha/BackgroundJobs/ErmSushiHarvester.t 2) Apply this patch and run tests again (they should pass this time). UI test: 1) Create a new data provider linked to Gale Cengage, service url: https://api.siqcloud.online/counterapi/r51 2) Add report release 5, customer id: '123', requestor id: '123', report types: 'TR_J1' 3) Run a report for this data provider, from Feb 2025 to Apr 2025. Notice that before applying patches, the job report results in a red bar with no error message. 4) Apply patches, repeat 3. Notice it now results in a nice error message. --- Koha/ERM/EUsage/UsageDataProvider.pm | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Koha/ERM/EUsage/UsageDataProvider.pm b/Koha/ERM/EUsage/UsageDataProvider.pm index cdb82e31d5f..b7acc76ab53 100644 --- a/Koha/ERM/EUsage/UsageDataProvider.pm +++ b/Koha/ERM/EUsage/UsageDataProvider.pm @@ -443,6 +443,24 @@ sub _check_trailing_character { return $url; } +=head3 sushi_code_is_error + + my $is_error = $self->sushi_code_is_error($code); + +Determines if a given SUSHI response code is considered an error. Codes greater than 1000 are generally errors unless they are in the list of known warning codes, in which case they are treated as non-errors. Docs at: +https://cop5.projectcounter.org/en/5.0.2/appendices/f-handling-errors-and-exceptions.html + +=cut + +sub _sushi_code_is_error { + my ($code) = @_; + + return 0 unless $code; + + my @warning_codes = ( 1011, 3032, 3040, 3050, 3060, 3061, 3062, 3070 ); + return 1 if $code > 1000 && !grep { $_ == $code } @warning_codes; +} + =head3 _sushi_errors Checks and handles possible errors in the SUSHI response @@ -457,12 +475,12 @@ sub _sushi_errors { my $message = $decoded_response->{Message} // $decoded_response->{message}; my $code = $decoded_response->{Code} // $decoded_response->{code}; - if ($severity) { + if ( $severity || _sushi_code_is_error($code) ) { $self->{job_callbacks}->{add_message_callback}->( { type => 'error', code => $code, - message => $severity . ' - ' . $message, + message => ( $severity ? "$severity - " : '' ) . $message, } ) if $self->{job_callbacks}; return 1; -- 2.39.5