From 20dabefe223c5feea60acc511d19d06a9ccf245d Mon Sep 17 00:00:00 2001 From: helderwiki Date: Wed, 30 Jul 2014 11:46:53 -0300 Subject: [PATCH] Improve error handling for HTTP requests The API provides more details about HTTP errors, so show these to the user instead of a generic "An unknown error occurred." Bug: 68767 Change-Id: I3188b9729c815a07c65a7dbef4d40deebe29b87d --- AbuseFilter.php | 3 +++ i18n/en.json | 3 ++- i18n/qqq.json | 3 ++- modules/ext.abuseFilter.edit.js | 8 ++++++-- modules/ext.abuseFilter.examine.js | 7 +++++-- modules/ext.abuseFilter.tools.js | 9 ++++++--- 6 files changed, 24 insertions(+), 9 deletions(-) diff --git a/AbuseFilter.php b/AbuseFilter.php index 8f57e2dd9..ab3d708c3 100644 --- a/AbuseFilter.php +++ b/AbuseFilter.php @@ -126,6 +126,7 @@ $wgResourceModules['ext.abuseFilter.edit'] = array( 'messages' => array( 'abusefilter-edit-syntaxok', 'abusefilter-edit-syntaxerr', + 'abusefilter-http-error', 'unknown-error', ), 'dependencies' => array( @@ -142,6 +143,7 @@ $wgResourceModules['ext.abuseFilter.tools'] = array( 'abusefilter-reautoconfirm-notallowed', 'abusefilter-reautoconfirm-none', 'abusefilter-reautoconfirm-done', + 'abusefilter-http-error', 'unknown-error', ), 'dependencies' => array( @@ -160,6 +162,7 @@ $wgResourceModules['ext.abuseFilter.examine'] = array( 'abusefilter-examine-syntaxerror', 'abusefilter-examine-notfound', 'abusefilter-mustbeeditor', + 'abusefilter-http-error', 'unknown-error', ), 'dependencies' => array( diff --git a/i18n/en.json b/i18n/en.json index ee959f173..3cddf5812 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -392,5 +392,6 @@ "abusefilter-diff-next": "Newer change", "abusefilter-import-intro": "You can use this interface to import filters from other wikis.\nOn the source wiki, click \"{{int:abusefilter-edit-export}}\" under \"{{int:abusefilter-edit-tools}}\" on the editing interface.\nCopy from the textbox that appears, and paste it into this textbox, then click \"{{int:abusefilter-import-submit}}\".", "abusefilter-import-submit": "Import data", - "abusefilter-group-default": "Default" + "abusefilter-group-default": "Default", + "abusefilter-http-error": "An HTTP error occurred: $1." } \ No newline at end of file diff --git a/i18n/qqq.json b/i18n/qqq.json index fb929955c..3987788cb 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -365,5 +365,6 @@ "abusefilter-diff-next": "Link to the diff view for the next change to this filter.\n\nSee also:\n* {{msg-mw|Abusefilter-diff-prev}}\n* {{msg-mw|Previousdiff}} and {{msg-mw|Nextdiff}}", "abusefilter-import-intro": "{{doc-important|Do not translate {{int:abusefilter-edit-export}}, {{int:abusefilter-tools-subtitle}}, and {{int:abusefilter-import-submit}} unless you absolute must substitute any of them.}}\n\nRefers to:\n* {{msg-mw|Abusefilter-edit-export}}\n* {{msg-mw|Abusefilter-edit-tools}}\n* {{msg-mw|Abusefilter-import-submit}}", "abusefilter-import-submit": "Used as label for the Submit button.\n\nPreceded by the textarea.\n\nUsed in:\n* {{msg-mw|Abusefilter-import-intro}}.", - "abusefilter-group-default": "The name for the default filter group. Most filters will be in this group.\n{{Identical|Default}}" + "abusefilter-group-default": "The name for the default filter group. Most filters will be in this group.\n{{Identical|Default}}", + "abusefilter-http-error": "Error message for HTTP requests. Parameters:\n* $1 - HTTP response code." } diff --git a/modules/ext.abuseFilter.edit.js b/modules/ext.abuseFilter.edit.js index ce21c34b4..9fe111094 100644 --- a/modules/ext.abuseFilter.edit.js +++ b/modules/ext.abuseFilter.edit.js @@ -100,10 +100,14 @@ /** * Acts on errors after doSyntaxCheck + * + * @param {string} error Error code returned from the AJAX request + * @param {Object} details Details about the error */ - function processSyntaxResultFailure() { + function processSyntaxResultFailure( error, details ) { + var msg = error === 'http' ? 'abusefilter-http-error' : 'unknown-error'; processSyntaxResultAlways( - mw.msg( 'unknown-error' ), + mw.msg( msg, details && details.exception ), 'mw-abusefilter-syntaxresult-error', false ); diff --git a/modules/ext.abuseFilter.examine.js b/modules/ext.abuseFilter.examine.js index 6c9e64373..aee39eff0 100644 --- a/modules/ext.abuseFilter.examine.js +++ b/modules/ext.abuseFilter.examine.js @@ -68,8 +68,9 @@ * Processes the results of the filter test in case of an error * * @param {string} error Error code returned from the AJAX request + * @param {Object} details Details about the error */ - function examinerTestProcessFailure( error ) { + function examinerTestProcessFailure( error, details ) { var msg; $.removeSpinner( 'filter-check' ); @@ -83,12 +84,14 @@ } else if ( error === 'permissiondenied' ) { // The 'abusefilter-modify' right is needed to use this API msg = 'abusefilter-mustbeeditor'; + } else if ( error === 'http' ) { + msg = 'abusefilter-http-error'; } else { msg = 'unknown-error'; } $syntaxResult - .text( mw.msg( msg ) ) + .text( mw.msg( msg, details && details.exception ) ) .show(); } diff --git a/modules/ext.abuseFilter.tools.js b/modules/ext.abuseFilter.tools.js index 2ba6b190c..637d44a8d 100644 --- a/modules/ext.abuseFilter.tools.js +++ b/modules/ext.abuseFilter.tools.js @@ -23,11 +23,11 @@ action: 'abusefilterevalexpression', expression: expr } ) - .fail( function() { + .fail( function( error, details ) { + var msg = error === 'http' ? 'abusefilter-http-error' : 'unknown-error'; $.removeSpinner( 'abusefilter-expr' ); - $( '#mw-abusefilter-expr-result' ) - .text( mw.msg( 'unknown-error' ) ); + .text( mw.msg( msg, details.exception ) ); } ) .done( function( data ) { $.removeSpinner( 'abusefilter-expr' ); @@ -89,6 +89,9 @@ case 'permissiondenied': msg = mw.msg( 'abusefilter-reautoconfirm-notallowed' ); break; + case 'http': + msg = mw.msg( 'abusefilter-http-error', data && data.exception ); + break; case 'notsuspended': msg = data.error.info; break;