From 9599aba8aebdd3c5ed5eec425837894d8a402ab4 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Wed, 17 Jun 2015 12:29:49 -0700 Subject: [PATCH] fix(nylas-api): Globally handle 401s and notify user they need to sign in Summary: Fixes T1843 Test Plan: No tests for this file yet Reviewers: evan Reviewed By: evan Maniphest Tasks: T1843 Differential Revision: https://phab.nylas.com/D1641 --- .../stylesheets/notifications.less | 3 ++- internal_packages/today/lib/main.cjsx | 2 +- src/flux/nylas-api.coffee | 23 ++++++++++++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/internal_packages/notifications/stylesheets/notifications.less b/internal_packages/notifications/stylesheets/notifications.less index 6662f72c3..19f475b17 100644 --- a/internal_packages/notifications/stylesheets/notifications.less +++ b/internal_packages/notifications/stylesheets/notifications.less @@ -15,7 +15,7 @@ .item { border-bottom:1px solid @border-color-divider; - + .inner { padding: @padding-large-vertical @padding-base-horizontal @padding-large-vertical @padding-base-horizontal; margin-top:3px; @@ -84,6 +84,7 @@ background-color: @background-color-info; } .notification-error { + background-color: @background-color-error; border-color: @background-color-error; color: @error-color; } diff --git a/internal_packages/today/lib/main.cjsx b/internal_packages/today/lib/main.cjsx index dfda9545e..37a066479 100644 --- a/internal_packages/today/lib/main.cjsx +++ b/internal_packages/today/lib/main.cjsx @@ -6,7 +6,7 @@ TodayIcon = require "./today-icon" module.exports = activate: (@state={}) -> - WorkspaceStore.defineSheet 'Today', {root: true, supportedModes: ['list'], name: 'Today', icon: TodayIcon}, + WorkspaceStore.defineSheet 'Today', {root: true, supportedModes: ['list'], name: 'Today', icon: 'today.png'}, list: ['RootSidebar', 'Today'] ComponentRegistry.register TodayView, diff --git a/src/flux/nylas-api.coffee b/src/flux/nylas-api.coffee index aad7bf80d..cae8ba8ac 100644 --- a/src/flux/nylas-api.coffee +++ b/src/flux/nylas-api.coffee @@ -122,8 +122,10 @@ class NylasAPI PriorityUICoordinator.settle.then => Actions.didMakeAPIRequest({request: options, response: response}) if error? or response.statusCode > 299 - if options.returnsModel and response.statusCode is 404 + if response.statusCode is 404 and options.returnsModel @_handleModel404(options.url) + if response.statusCode is 401 + @_handle401(options.url) if options.error options.error(new APIError({error, response, body})) else @@ -163,6 +165,25 @@ class NylasAPI DatabaseStore.find(klass, klassId).then (model) -> DatabaseStore.unpersistModel(model) if model + _handle401: (url) -> + # Throw up a notification indicating that the user should log out and log back in + Actions.postNotification + type: 'error' + tag: '401' + sticky: true + message: "Nylas can no longer authenticate with your mail provider. You will not be able to send or receive mail. Please log out and sign in again.", + icon: 'fa-sign-out' + actions: [{ + label: 'Log Out' + id: '401:logout' + }] + + unless @_notificationUnlisten + handler = ({notification, action}) -> + if action.id is '401:logout' + atom.logout() + @_notificationUnlisten = Actions.notificationActionTaken.listen(handler, @) + _handleDeltas: (deltas) -> Actions.longPollReceivedRawDeltas(deltas) console.log("Processing Deltas")