mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-27 15:30:42 +00:00
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
This commit is contained in:
parent
f73b148a82
commit
20dabefe22
|
@ -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(
|
||||
|
|
|
@ -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."
|
||||
}
|
|
@ -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 <code><nowiki>{{int:abusefilter-edit-export}}</nowiki></code>, <code><nowiki>{{int:abusefilter-tools-subtitle}}</nowiki></code>, and <code><nowiki>{{int:abusefilter-import-submit}}</nowiki></code> 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."
|
||||
}
|
||||
|
|
|
@ -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
|
||||
);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue