From: Tara L Andrews Date: Mon, 10 Jun 2013 06:19:29 +0000 (+0200) Subject: correct error handling at session timeout: issue #3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=21e6ebc7ffd87340286aa4ee5d4df1057bac6a3b;p=scpubgit%2Fstemmaweb.git correct error handling at session timeout: issue #3 --- diff --git a/root/js/relationship.js b/root/js/relationship.js index 14c0676..873945b 100644 --- a/root/js/relationship.js +++ b/root/js/relationship.js @@ -703,12 +703,22 @@ $(document).ready(function () { $("#dialog_overlay").hide(); } }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) { - 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.

' ); - } - $(event.target).parent().find('.ui-button').button("enable"); + if( ajaxSettings.url == getTextURL('relationships') + && ajaxSettings.type == 'POST' && jqXHR.status == 403 ) { + var error; + if( jqXHR.responseText.indexOf('do not have permission to modify') > -1 ) { + error = 'You are not authorized to modify this tradition. (Try logging in again?)'; + } else { + try { + var errobj = jQuery.parseJSON( jqXHR.responseText ); + error = errobj.error + '
The relationship cannot be made.

'; + } catch(e) { + error = jqXHR.responseText; + } + } + $('#status').append( '

Error: ' + error ); + } + $(event.target).parent().find('.ui-button').button("enable"); } ); } @@ -833,12 +843,22 @@ $(document).ready(function () { $("#dialog_overlay").hide(); } }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) { - if( ajaxSettings.url.lastIndexOf( getReadingURL('') ) > -1 + if( ajaxSettings.url.lastIndexOf( getReadingURL('') ) > -1 && ajaxSettings.type == 'POST' && jqXHR.status == 403 ) { - var errobj = jQuery.parseJSON( jqXHR.responseText ); - $('#reading_status').append( '

Error: ' + errobj.error + '

' ); - } - $(event.target).parent().find('.ui-button').button("enable"); + var error; + if( jqXHR.responseText.indexOf('do not have permission to modify') > -1 ) { + error = 'You are not authorized to modify this tradition. (Try logging in again?)'; + } else { + try { + var errobj = jQuery.parseJSON( jqXHR.responseText ); + error = errobj.error + '
The relationship cannot be made.

'; + } catch(e) { + error = jqXHR.responseText; + } + } + $('#status').append( '

Error: ' + error ); + } + $(event.target).parent().find('.ui-button').button("enable"); }); } else { $('#reading-form').hide();