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
This commit is contained in:
Ben Gotow 2015-06-17 12:29:49 -07:00
parent e10f402d3d
commit 9599aba8ae
3 changed files with 25 additions and 3 deletions

View file

@ -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;
}

View file

@ -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,

View file

@ -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")