mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-09-06 12:44:30 +08:00
fix(onboarding): fix error handling for invalid account data from server
Summary: Change `addAccountFromJSON` in `AccountStore` to throw an exception when it encounters invalid data, instead of calling `atom.emitError()`. Just calling `emitError` doesn't throw an exception, so the code proceeds as if an account has been added. Instead, call `emitError` from AccountSettingsPage, and display an error message to the user. Test Plan: manual Reviewers: bengotow Reviewed By: bengotow Subscribers: evan Differential Revision: https://phab.nylas.com/D2116
This commit is contained in:
parent
b38ca54b45
commit
62fb708797
2 changed files with 14 additions and 5 deletions
|
@ -45,7 +45,7 @@ class AccountSettingsPage extends React.Component
|
|||
{data} = account_data
|
||||
# accountJson = @_decrypt(data, @state.provider.encryptionKey, @state.provider.encryptionIv)
|
||||
account = JSON.parse(data)
|
||||
OnboardingActions.accountJSONReceived(account)
|
||||
@_onAccountReceived(account)
|
||||
else if tries < 20 and id is pollAttemptId
|
||||
setTimeout(_retry, delay)
|
||||
delay *= 1.2 # exponential backoff
|
||||
|
@ -251,11 +251,21 @@ class AccountSettingsPage extends React.Component
|
|||
method: "POST"
|
||||
timeout: 30000
|
||||
body: json
|
||||
success: (json) =>
|
||||
OnboardingActions.accountJSONReceived(json)
|
||||
success: @_onAccountReceived
|
||||
error: @_onNetworkError
|
||||
.catch(@_onNetworkError)
|
||||
|
||||
_onAccountReceived: (json) =>
|
||||
try
|
||||
OnboardingActions.accountJSONReceived(json)
|
||||
catch e
|
||||
atom.emitError(e)
|
||||
@setState
|
||||
tryingToAuthenticate: false
|
||||
errorMessage: "Sorry, something went wrong on the Nylas server. Please try again. If you're still having issues, contact us at support@nylas.com."
|
||||
@_resize()
|
||||
|
||||
|
||||
_onNetworkError: (err) =>
|
||||
errorMessage = err.message
|
||||
if errorMessage == "Invite code required"
|
||||
|
|
|
@ -79,8 +79,7 @@ class AccountStore
|
|||
if not json.email_address or not json.provider
|
||||
console.error("Returned account data is invalid", json)
|
||||
console.log JSON.stringify(json)
|
||||
atom.emitError(new Error("Returned account data is invalid"))
|
||||
return
|
||||
throw new Error("Returned account data is invalid")
|
||||
return if @_tokens[json.id]
|
||||
@_tokens[json.id] = json.auth_token
|
||||
@_accounts.push((new Account).fromJSON(json))
|
||||
|
|
Loading…
Add table
Reference in a new issue