From bfa7c3d18ebd9428c4a2cf359b8e06d4565b7349 Mon Sep 17 00:00:00 2001 From: David Gustafsson Date: Thu, 29 Feb 2024 19:12:24 +0100 Subject: [PATCH] Bug 18138: Display error when template missing in advanced editor --- .../intranet-tmpl/lib/koha/cateditor/koha-backend.js | 12 ++++++++++-- .../intranet-tmpl/prog/en/includes/cateditor-ui.inc | 2 ++ svc/bib | 9 ++++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/koha-backend.js b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/koha-backend.js index 5410f775633..d51e1727e99 100644 --- a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/koha-backend.js +++ b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/koha-backend.js @@ -23,6 +23,14 @@ define( [ '/cgi-bin/koha/svc/cataloguing/framework?frameworkcode=&callback=defin var _framework_mappings = {}; var _framework_kohafields = {}; + function _biblioSaveError( data ) { + var error; + if (data.responseXML) { + error = $(data.responseXML).find('error').first().text(); + } + return error || _('Could not save record'); + } + function _fromXMLStruct( data ) { result = {}; @@ -148,7 +156,7 @@ define( [ '/cgi-bin/koha/svc/cataloguing/framework?frameworkcode=&callback=defin } callback( record ); } ).fail( function( data ) { - callback( { error: _('Could not save record') } ); + callback( { error: _biblioSaveError( data ) } ); } ); }, @@ -169,7 +177,7 @@ define( [ '/cgi-bin/koha/svc/cataloguing/framework?frameworkcode=&callback=defin } callback( record ); } ).fail( function( data ) { - callback( { error: _('Could not save record') } ); + callback( { error: _biblioSaveError( data ) } ); } ); }, diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc index 2ff15873b0c..7d26f52ff0d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc @@ -1108,6 +1108,8 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr humanMsg.displayAlert( _("Incorrect syntax, cannot save"), { className: 'humanError' } ); } else if ( result.error == 'invalid' ) { humanMsg.displayAlert( _("Record structure invalid, cannot save"), { className: 'humanError' } ); + } else if ( result.error == 'missing_marc_modification_template' ) { + humanMsg.displayAlert( _("Missing marc modification template, cannot save"), { className: 'humanError' } ); } else if ( result.error ) { humanMsg.displayAlert( _("Something went wrong, cannot save"), { className: 'humanError' } ); } else if ( !result.error ) { diff --git a/svc/bib b/svc/bib index 7d055af3ce2..62c99c1b139 100755 --- a/svc/bib +++ b/svc/bib @@ -102,10 +102,11 @@ sub update_bib { my $result = {}; my $inxml = $query->param('POSTDATA'); - print $query->header(-type => 'text/xml', -charset => 'utf-8'); my $record = eval {MARC::Record::new_from_xml( $inxml, "UTF-8", C4::Context->preference('marcflavour'))}; my $do_not_escape = 0; + + if ($@) { $result->{'status'} = "failed"; $result->{'error'} = $@; @@ -134,7 +135,9 @@ sub update_bib { if ($template) { ModifyRecordWithTemplate( $template_id, $record ); } else { - croak "No MARC modification template exists with id \"$template_id\""; + print $query->header(-type => 'text/xml', -status => '500 Internal Server Error'); + print XMLout({ error => 'missing_marc_modification_template' }, NoAttr => 1, RootName => 'response', XMLDecl => 1); + exit 0; } } @@ -149,7 +152,7 @@ sub update_bib { $result->{'marcxml'} = $xml; $do_not_escape = 1; } - + print $query->header(-type => 'text/xml', -charset => 'utf-8'); print XMLout($result, NoAttr => 1, RootName => 'response', XMLDecl => 1, NoEscape => $do_not_escape); } -- 2.43.0