fix(identity): properly post to identity endpoint

This commit is contained in:
Evan Morikawa 2017-02-03 19:27:56 -08:00
parent 1448be8606
commit 8f241048de
4 changed files with 23 additions and 6 deletions

View file

@ -1,6 +1,7 @@
import {remote} from 'electron'
import _ from 'underscore';
import {Actions, NylasAPIHelpers, AccountStore, DatabaseStore, Message,
CategoryStore} from 'nylas-exports';
import {FeatureUsageStore, Actions, NylasAPIHelpers, AccountStore,
DatabaseStore, Message, CategoryStore} from 'nylas-exports';
import SnoozeUtils from './snooze-utils'
import {PLUGIN_ID, PLUGIN_NAME} from './snooze-constants';
import SnoozeActions from './snooze-actions';
@ -68,12 +69,22 @@ class SnoozeStore {
};
onSnoozeThreads = (threads, snoozeDate, label) => {
if (!FeatureUsageStore.isUsable("snooze")) {
remote.dialog.showMessageBox({
title: 'Out of snoozes',
detail: `You have used your monthly quota of Snoozes`,
buttons: ['OK'],
type: 'info',
});
return Promise.resolve()
}
this.recordSnoozeEvent(threads, snoozeDate, label)
const accounts = AccountStore.accountsForItems(threads)
const promises = accounts.map((acc) => {
return NylasAPIHelpers.authPlugin(this.pluginId, this.pluginName, acc)
})
return Promise.all(promises)
.then(() => {
return SnoozeUtils.moveThreadsToSnooze(threads, this.snoozeCategoriesPromise, snoozeDate)
@ -96,6 +107,8 @@ class SnoozeStore {
}
});
});
}).then(() => {
return FeatureUsageStore.useFeature('snooze')
})
.catch((error) => {
SnoozeUtils.moveThreadsFromSnooze(threads, this.snoozeCategoriesPromise)

2
src/K2

@ -1 +1 @@
Subproject commit a400ce3ce9c19db1fc941fb9f3ebdd3892796630
Subproject commit 7dbdd771b0764b1a6e1509a67876694501678889

View file

@ -14,7 +14,7 @@ class _EdgehillAPI {
_onConfigChanged = () => {
const env = NylasEnv.config.get('env')
if (['development', 'local'].includes(env)) {
this.APIRoot = "http://localhost:5009";
this.APIRoot = "http://n1-auth.lvh.me:5555";
} else if (env === 'experimental') {
this.APIRoot = "https://edgehill-experimental.nylas.com";
} else if (env === 'staging') {

View file

@ -208,15 +208,19 @@ class IdentityStore extends NylasStore {
startTime: Date.now(),
};
try {
await this.nylasIDRequest(options)
const newIdentity = await this.nylasIDRequest(options);
return newIdentity
} catch (err) {
const error = err || new Error(`IdentityStore.fetchPath: ${path} ${err.message}.`)
NylasEnv.reportError(error)
return null
}
}
nylasIDRequest(options) {
return new Promise((resolve, reject) => {
options.formData = false
options.json = true
options.auth = {
username: this._identity.token,
password: '',
@ -236,7 +240,7 @@ class IdentityStore extends NylasStore {
});
if (response.statusCode === 200) {
try {
return resolve(JSON.parse(body));
return resolve(body);
} catch (err) {
return reject(err)
}