mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-09-07 05:04:58 +08:00
[client-app] Prevent from making any requests when NylasID isn't present
Summary: Sometimes, when logging out of your NylasID and restarting the app, we would continue making some requests from the worker window that required a NylasID. This would make the app enter a restart loop and become completely unresponsive because when we made a request without a NylasID, we would force the user to log out and restart the app, and then we would again make the requests without the id, ad infinitum. To fix this, we make sure we have a NylasID before making any requests that require it Test Plan: manual Reviewers: halla, evan Reviewed By: halla, evan Differential Revision: https://phab.nylas.com/D4344
This commit is contained in:
parent
2095f0907e
commit
d1b81b6afe
4 changed files with 33 additions and 21 deletions
|
@ -1,6 +1,7 @@
|
|||
import _ from 'underscore'
|
||||
import moment from 'moment-timezone'
|
||||
import {
|
||||
IdentityStore,
|
||||
AccountStore,
|
||||
NylasAPI,
|
||||
NylasAPIRequest,
|
||||
|
@ -32,7 +33,8 @@ class ContactRankingsCache extends RefreshingJSONCache {
|
|||
}
|
||||
|
||||
fetchData = (callback) => {
|
||||
if (NylasEnv.inSpecMode()) return
|
||||
if (NylasEnv.inSpecMode()) { return }
|
||||
if (!IdentityStore.identity()) { return }
|
||||
|
||||
const request = new NylasAPIRequest({
|
||||
api: NylasAPI,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import {ipcRenderer} from 'electron'
|
||||
import {AccountStore, Actions, NylasAPI, NylasAPIRequest} from 'nylas-exports'
|
||||
import {IdentityStore, AccountStore, Actions, NylasAPI, NylasAPIRequest} from 'nylas-exports'
|
||||
|
||||
const CHECK_HEALTH_INTERVAL = 5 * 60 * 1000;
|
||||
|
||||
|
@ -35,6 +35,9 @@ class SyncHealthChecker {
|
|||
|
||||
_checkSyncHealth = async () => {
|
||||
try {
|
||||
if (!IdentityStore.identity()) {
|
||||
return
|
||||
}
|
||||
const request = this._buildRequest()
|
||||
const response = await request.run()
|
||||
this._lastSyncActivity = response
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import AccountStore from './stores/account-store'
|
||||
import IdentityStore from './stores/identity-store'
|
||||
import NylasAPIRequest from './nylas-api-request';
|
||||
|
||||
// We're currently moving between services hosted on edgehill-api (written in
|
||||
|
@ -34,6 +35,9 @@ class _EdgehillAPI {
|
|||
}
|
||||
|
||||
if (options.authWithNylasAPI) {
|
||||
if (!IdentityStore.identity()) {
|
||||
throw new Error('LegacyEdgehillAPI.makeRequest: Identity must be present to make a request that auths with Nylas API')
|
||||
}
|
||||
// The account doesn't matter for Edgehill server. We just need to
|
||||
// ensure it's a valid account.
|
||||
options.accountId = AccountStore.accounts()[0].id;
|
||||
|
|
|
@ -57,27 +57,30 @@ class MetricsReporter {
|
|||
})
|
||||
|
||||
try {
|
||||
if (isClientEnv()) {
|
||||
if (NylasEnv.inDevMode()) { return }
|
||||
|
||||
if (!dataToReport.accountId) {
|
||||
throw new Error("Metrics Reporter: You must include an accountId");
|
||||
}
|
||||
|
||||
const {N1CloudAPI, NylasAPIRequest} = require('nylas-exports') // eslint-disable-line
|
||||
const req = new NylasAPIRequest({
|
||||
api: N1CloudAPI,
|
||||
options: {
|
||||
path: `/ingest-metrics`,
|
||||
method: 'POST',
|
||||
body: dataToReport,
|
||||
accountId: dataToReport.accountId,
|
||||
},
|
||||
});
|
||||
await req.run()
|
||||
} else {
|
||||
if (!isClientEnv()) {
|
||||
this.sendToHoneycomb(dataToReport)
|
||||
return
|
||||
}
|
||||
if (NylasEnv.inDevMode()) { return }
|
||||
|
||||
const {IdentityStore, N1CloudAPI, NylasAPIRequest} = require('nylas-exports') // eslint-disable-line
|
||||
if (!IdentityStore.identity()) {
|
||||
throw new Error("Metrics Reporter: Identity must be available");
|
||||
}
|
||||
if (!dataToReport.accountId) {
|
||||
throw new Error("Metrics Reporter: You must include an accountId");
|
||||
}
|
||||
|
||||
const req = new NylasAPIRequest({
|
||||
api: N1CloudAPI,
|
||||
options: {
|
||||
path: `/ingest-metrics`,
|
||||
method: 'POST',
|
||||
body: dataToReport,
|
||||
accountId: dataToReport.accountId,
|
||||
},
|
||||
});
|
||||
await req.run()
|
||||
logger.log("Metrics Reporter: Submitted.", dataToReport);
|
||||
} catch (err) {
|
||||
logger.warn("Metrics Reporter: Submission Failed.", {error: err, ...dataToReport});
|
||||
|
|
Loading…
Add table
Reference in a new issue