From: Tara L Andrews Date: Thu, 7 Jun 2012 00:05:44 +0000 (+0200) Subject: add error handling for reading morphology update X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6666d1110a2a09fc7adca2976ca322ea5210f2a4;p=scpubgit%2Fstemmaweb.git add error handling for reading morphology update --- diff --git a/lib/stemmaweb/Controller/Relation.pm b/lib/stemmaweb/Controller/Relation.pm index 4bae11d..8785d6f 100644 --- a/lib/stemmaweb/Controller/Relation.pm +++ b/lib/stemmaweb/Controller/Relation.pm @@ -298,12 +298,14 @@ sub reading :Chained('text') :PathPart :Args(1) { $c->stash->{'result'} = $rdg ? _reading_struct( $rdg ) : { 'error' => "No reading with ID $reading_id" }; } elsif ( $c->request->method eq 'POST' ) { + my $errmsg; # Are we re-lemmatizing? if( $c->request->param('relemmatize') ) { my $nf = $c->request->param('normal_form'); # TODO throw error unless $nf $rdg->normal_form( $nf ); # TODO throw error if lemmatization fails + # TODO skip this if normal form hasn't changed $rdg->lemmatize(); } else { # Set all the values that we have for the reading. @@ -320,9 +322,14 @@ sub reading :Chained('text') :PathPart :Args(1) { unless( defined $idx ) { # Make the word form and add it to the lexeme. $c->log->debug("Adding new form for $strrep"); - $idx = $lx->add_matching_form( $strrep ) - 1; + try { + $idx = $lx->add_matching_form( $strrep ) - 1; + } catch( Text::Tradition::Error $e ) { + $c->response->status( '403' ); + $errmsg = $e->message; + } } - $lx->disambiguate( $idx ); + $lx->disambiguate( $idx ) if defined $idx; } elsif( $read_write_keys{$p} ) { my $val = _clean_booleans( $rdg, $p, $c->request->param( $p ) ); $rdg->$p( $val ); @@ -330,7 +337,8 @@ sub reading :Chained('text') :PathPart :Args(1) { } } $m->save( $tradition ); - $c->stash->{'result'} = _reading_struct( $rdg ); + $c->stash->{'result'} = $errmsg ? { 'error' => $errmsg } + : _reading_struct( $rdg ); } $c->forward('View::JSON'); diff --git a/root/js/relationship.js b/root/js/relationship.js index 0c34643..3fa40d1 100644 --- a/root/js/relationship.js +++ b/root/js/relationship.js @@ -692,7 +692,8 @@ $(document).ready(function () { $("#dialog_overlay").hide(); } }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) { - if( ( ajaxSettings.type == 'POST' ) && jqXHR.status == 403 ) { + if( ajaxSettings.url == getTextURL('relationships') + && ajaxSettings.type == 'POST' && jqXHR.status == 403 ) { var errobj = jQuery.parseJSON( jqXHR.responseText ); $('#status').append( '

Error: ' + errobj.error + '
The relationship cannot be made.

' ); } @@ -747,6 +748,7 @@ $(document).ready(function () { $( this ).dialog( "close" ); }, Update: function() { + $('#reading_status').empty(); var reading_id = $('#reading_id').val() form_values = { 'id' : reading_id, @@ -781,6 +783,7 @@ $(document).ready(function () { open: function() { $(".ui-widget-overlay").css("background", "none"); $("#dialog_overlay").show(); + $('#reading_status').empty(); $("#dialog_overlay").height( $("#enlargement_container").height() ); $("#dialog_overlay").width( $("#enlargement_container").innerWidth() ); $("#dialog_overlay").offset( $("#enlargement_container").offset() ); @@ -788,6 +791,12 @@ $(document).ready(function () { close: function() { $("#dialog_overlay").hide(); } + }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) { + if( ajaxSettings.url.lastIndexOf( getReadingURL('') ) > -1 + && ajaxSettings.type == 'POST' && jqXHR.status == 403 ) { + var errobj = jQuery.parseJSON( jqXHR.responseText ); + $('#reading_status').append( '

Error: ' + errobj.error + '

' ); + } }); diff --git a/root/src/relate.tt b/root/src/relate.tt index 3e35dc7..49afb7b 100644 --- a/root/src/relate.tt +++ b/root/src/relate.tt @@ -93,6 +93,7 @@ $(document).ready(function () {
+