From f04dd671aff9c753676eb96b14bff470d942c0e8 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 2 Feb 2023 16:17:06 +0000 Subject: [PATCH] Bug 32121: (QA follow-up) Use error_code rather than key We semi-recently introduced error_code into our error object to allow for translation and code paths for different errors without having to rely on long description string matches. This QA follow-up converts the existing match and new 'key' fields introduced in this patchset to use the updated 'error_code' key. Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- Koha/REST/V1/Items.pm | 32 +++++++++++-------- .../prog/en/modules/catalogue/detail.tt | 8 ++--- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/Koha/REST/V1/Items.pm b/Koha/REST/V1/Items.pm index 3f39009db4..087deb3fab 100644 --- a/Koha/REST/V1/Items.pm +++ b/Koha/REST/V1/Items.pm @@ -290,35 +290,41 @@ sub add_to_bundle { return $c->render( status => 409, openapi => { - error => 'Item is already bundled', - key => $_->duplicate_id + error => 'Item is already bundled', + error_code => 'already_bundled', + key => $_->duplicate_id } ); } - elsif ( ref($_) eq 'Koha::Exceptions::Item::Bundle::IsBundle' ) { + elsif ( ref($_) eq 'Koha::Exceptions::Item::Bundle::ItemIsCheckedOut' ) + { return $c->render( - status => 400, + status => 409, openapi => { - error => 'Bundles cannot be nested' + error => 'Item is checked out', + error_code => 'checked_out' } ); - } elsif (ref($_) eq 'Koha::Exceptions::Item::Bundle::ItemIsCheckedOut') { + } + elsif ( ref($_) eq 'Koha::Exceptions::Checkin::FailedCheckin' ) { return $c->render( status => 409, openapi => { - error => 'Item is checked out', - key => 'checked_out' + error => 'Item cannot be checked in', + error_code => 'failed_checkin' } ); - } elsif (ref($_) eq 'Koha::Exceptions::Checkin::FailedCheckin') { + } + elsif ( ref($_) eq 'Koha::Exceptions::Item::Bundle::IsBundle' ) { return $c->render( - status => 409, + status => 400, openapi => { - error => 'Item cannot be checked in', - key => 'failed_checkin' + error => 'Bundles cannot be nested', + error_code => 'failed_nesting' } ); - } else { + } + else { $c->unhandled_exception($_); } }; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt index 7a34ce04d6..aeda09d0e7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -1957,9 +1957,9 @@ Note that permanent location is a code, and location may be an authval. posting.fail(function(data) { if ( data.status === 409 ) { var response = data.responseJSON; - if ( response.key === "PRIMARY" ) { + if ( response.error_code === 'already_bundled' ) { $('#addResult').replaceWith('
'+_("Warning: Item '%s' already attached").format(barcode)+'
'); - } else if (response.key === 'checked_out') { + } else if (response.error_code === 'checked_out') { const button = $('