diff --git a/Resources.php b/Resources.php index 8f18715f0..c92082dcf 100644 --- a/Resources.php +++ b/Resources.php @@ -199,6 +199,7 @@ $wgResourceModules += array( ), 'messages' => array( 'echo-api-failure', + 'echo-notification-loginrequired', 'echo-api-failure-cross-wiki', ), 'targets' => array( 'desktop', 'mobile' ), diff --git a/modules/controller/mw.echo.Controller.js b/modules/controller/mw.echo.Controller.js index 85228a025..59cb7711d 100644 --- a/modules/controller/mw.echo.Controller.js +++ b/modules/controller/mw.echo.Controller.js @@ -226,7 +226,16 @@ controller.manager.getLocalCounter().update(); return dateItemIds; - } ); + } ) + .then( + null, + function ( errCode, errObj ) { + return { + errCode: errCode, + errInfo: OO.getProp( errObj, 'error', 'info' ) + }; + } + ); }; /** * Fetch notifications from the local API and update the notifications list. diff --git a/modules/ui/mw.echo.ui.NotificationBadgeWidget.js b/modules/ui/mw.echo.ui.NotificationBadgeWidget.js index c81e59ccf..9a5d6b9ed 100644 --- a/modules/ui/mw.echo.ui.NotificationBadgeWidget.js +++ b/modules/ui/mw.echo.ui.NotificationBadgeWidget.js @@ -357,8 +357,14 @@ } }, // Failure - function () { - widget.notificationsWidget.resetLoadingOption( mw.msg( 'echo-api-failure' ) ); + function ( errorObj ) { + if ( errorObj.errCode === 'notlogin-required' ) { + // Login required message + widget.notificationsWidget.resetLoadingOption( mw.msg( 'echo-notification-loginrequired' ) ); + } else { + // Generic API failure message + widget.notificationsWidget.resetLoadingOption( mw.msg( 'echo-api-failure' ) ); + } } ) .then( this.emit.bind( this, 'finishLoading' ) ) diff --git a/modules/ui/mw.echo.ui.NotificationsInboxWidget.js b/modules/ui/mw.echo.ui.NotificationsInboxWidget.js index 20dd730ea..4e1df7745 100644 --- a/modules/ui/mw.echo.ui.NotificationsInboxWidget.js +++ b/modules/ui/mw.echo.ui.NotificationsInboxWidget.js @@ -29,6 +29,8 @@ this.$overlay = config.$overlay || this.$element; this.limit = config.limit || 25; + this.error = false; + // A notice or error message widget this.noticeMessageWidget = new OO.ui.LabelWidget( { classes: [ 'mw-echo-ui-notificationsInboxWidget-notice' ] @@ -236,6 +238,7 @@ } this.pushPending(); + this.error = false; return fetchPromise .then( // Success @@ -245,8 +248,21 @@ widget.controller.updateSeenTimeForCurrentSource(); }, // Failure - this.popPending.bind( this ) - ); + function ( errObj ) { + var msg; + if ( errObj.errCode === 'notlogin-required' ) { + // Login required message + msg = mw.msg( 'echo-notification-loginrequired' ); + } else { + // Generic API failure message + msg = mw.msg( 'echo-api-failure' ); + } + widget.error = true; + widget.noticeMessageWidget.setLabel( msg ); + widget.displayMessage( true ); + } + ) + .always( this.popPending.bind( this ) ); }; /** @@ -265,7 +281,10 @@ * Extend the popPending method to enable UI elements */ mw.echo.ui.NotificationsInboxWidget.prototype.popPending = function () { - this.resetMessageLabel(); + if ( !this.error ) { + this.resetMessageLabel(); + } + this.topPaginationWidget.setDisabled( false ); this.bottomPaginationWidget.setDisabled( false ); diff --git a/modules/ui/mw.echo.ui.NotificationsWrapper.js b/modules/ui/mw.echo.ui.NotificationsWrapper.js index 500d54cff..d7d544f20 100644 --- a/modules/ui/mw.echo.ui.NotificationsWrapper.js +++ b/modules/ui/mw.echo.ui.NotificationsWrapper.js @@ -65,6 +65,15 @@ this.pushPending(); return this.controller.fetchLocalNotifications( true ) + .then( null, function ( errorObj ) { + if ( errorObj.errCode === 'notlogin-required' ) { + // Login required message + widget.notificationsWidget.resetLoadingOption( mw.msg( 'echo-notification-loginrequired' ) ); + } else { + // Generic API failure message + widget.notificationsWidget.resetLoadingOption( mw.msg( 'echo-api-failure' ) ); + } + } ) .always( function () { widget.popPending(); widget.emit( 'finishLoading' );