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 <martin.renvoize@ptfs-europe.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit f04dd671af)
Signed-off-by: Jacob O'Mara <jacobomara901@gmail.com>
This commit is contained in:
Martin Renvoize 2023-02-02 16:17:06 +00:00 committed by Jacob O'Mara
parent 320b29cbde
commit b0015f7124
2 changed files with 31 additions and 25 deletions

View File

@ -226,35 +226,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::ItemIsCheckedOut' )
{
return $c->render(
status => 409,
openapi => {
error => 'Item is checked out',
error_code => 'checked_out'
}
);
}
elsif ( ref($_) eq 'Koha::Exceptions::Checkin::FailedCheckin' ) {
return $c->render(
status => 409,
openapi => {
error => 'Item cannot be checked in',
error_code => 'failed_checkin'
}
);
}
elsif ( ref($_) eq 'Koha::Exceptions::Item::Bundle::IsBundle' ) {
return $c->render(
status => 400,
status => 400,
openapi => {
error => 'Bundles cannot be nested'
error => 'Bundles cannot be nested',
error_code => 'failed_nesting'
}
);
} elsif (ref($_) eq 'Koha::Exceptions::Item::Bundle::ItemIsCheckedOut') {
return $c->render(
status => 409,
openapi => {
error => 'Item is checked out',
key => 'checked_out'
}
);
} elsif (ref($_) eq 'Koha::Exceptions::Checkin::FailedCheckin') {
return $c->render(
status => 409,
openapi => {
error => 'Item cannot be checked in',
key => 'failed_checkin'
}
);
} else {
}
else {
$c->unhandled_exception($_);
}
};

View File

@ -1799,9 +1799,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('<div id="addResult" class="alert alert-warning">'+_("Warning: Item '%s' already attached").format(barcode)+'</div>');
} else if (response.key === 'checked_out') {
} else if (response.error_code === 'checked_out') {
const button = $('<button type="button">')
.addClass('btn btn-xs')
.text(__('Check in and add to bundle'))
@ -1813,7 +1813,7 @@ Note that permanent location is a code, and location may be an authval.
.attr('class', 'alert alert-warning')
.append(__x('Warning: Item {barcode} is checked out', { barcode }))
.append(' ', button);
} else if (response.key === 'failed_checkin') {
} else if (response.error_code === 'failed_checkin') {
$('#addResult')
.empty()
.attr('class', 'alert alert-danger')
@ -1825,7 +1825,7 @@ Note that permanent location is a code, and location may be an authval.
$('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">'+_("Failure: Item '%s' not found").format(barcode)+'</div>');
} else if ( data.status === 400 ) {
var response = data.responseJSON;
if ( response.error === "Bundles cannot be nested" ) {
if ( response.error_code === "failed_nesting" ) {
$('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">'+_("Failure: Item '%s' is a bundle and bundles cannot be nested").format(barcode)+'</div>');
} else {
$('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">'+_("Failure: Check the logs for details")+'</div>');