r100803 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100802‎ | r100803 | r100804 >
Date:12:45, 26 October 2011
Author:werdna
Status:ok
Tags:
Comment:
Improve error handling
Modified paths:
  • /trunk/extensions/MoodBar/MoodBar.i18n.php (modified) (history)
  • /trunk/extensions/MoodBar/MoodBar.php (modified) (history)
  • /trunk/extensions/MoodBar/modules/ext.moodBar.dashboard/ext.moodBar.dashboard.js (modified) (history)

Diff [purge]

Index: trunk/extensions/MoodBar/MoodBar.i18n.php
@@ -102,6 +102,7 @@
103103 'moodbar-restore-header' => "Restore this item's visibility",
104104 'moodbar-restore-intro' => '',
105105 'moodbar-invalid-item' => 'The system was unable to find the correct feedback item.',
 106+ 'moodbar-feedback-action-error' => 'An error occurred when trying to perform this action.',
106107 // Mood types
107108 'moodbar-type-happy' => 'Happy',
108109 'moodbar-type-sad' => 'Sad',
Index: trunk/extensions/MoodBar/modules/ext.moodBar.dashboard/ext.moodBar.dashboard.js
@@ -224,8 +224,11 @@
225225 } else {
226226 // Failure, just remove the link.
227227 $item.find('.fbd-item-show').remove();
 228+ $item.find('.mw-ajax-loader').remove();
 229+ showItemError( $item );
228230 }
229 - }, 'json' );
 231+ }, 'json' )
 232+ .error( function() { showItemError( $item ); } );
230233 }
231234
232235 /**
@@ -243,11 +246,27 @@
244247 }
245248
246249 /**
 250+ * Show an error on an individual item
 251+ * @param $item The .fbd-item to show the message on
 252+ * @param message The message to show (currently ignored)
 253+ */
 254+ function showItemError( $item, message ) {
 255+ $item.find('.mw-ajax-loader').remove();
 256+ $('<div class="error"/>')
 257+ .text( mw.msg('moodbar-feedback-action-error') )
 258+ .prependTo($item);
 259+ }
 260+
 261+ /**
247262 * Execute an action on an item
248263 */
249264 function doAction( params, $item ) {
250265 var item_id = $item.data('mbccontinue').split('|')[1];
251266
 267+ var errorHandler = function(error_str) {
 268+ showItemError( $item, error_str );
 269+ };
 270+
252271 $.post( mw.util.wikiScript('api'),
253272 $.extend( {
254273 'action' : 'feedbackdashboard',
@@ -260,12 +279,15 @@
261280 if ( response.feedbackdashboard.result == 'success' ) {
262281 reloadItem( $item );
263282 } else {
264 - alert( response.feedbackdashboard.error );
 283+ errorHandler( response.feedbackdashboard.error );
265284 }
 285+ } else if ( response && response.error ) {
 286+ errorHandler( response.error.message );
266287 } else {
267 - alert('Unknown error');
 288+ errorHandler();
268289 }
269 - } );
 290+ } )
 291+ .error( errorHandler );
270292 }
271293
272294 /**
Index: trunk/extensions/MoodBar/MoodBar.php
@@ -141,7 +141,8 @@
142142 'messages' => array(
143143 'moodbar-feedback-nomore',
144144 'moodbar-feedback-noresults',
145 - 'moodbar-feedback-ajaxerror'
 145+ 'moodbar-feedback-ajaxerror',
 146+ 'moodbar-feedback-action-error',
146147 ),
147148 );
148149

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r100793FeedbackDashboard: Rearrange to allow showing/hiding by AJAX. Also make sure ...werdna06:02, 26 October 2011

Status & tagging log