Skip to content

Commit 184787d

Browse files
author
Sergey Slipchenko
authored
Fix sentry errors (#380)
1 parent 40fb5b1 commit 184787d

File tree

2 files changed

+55
-48
lines changed

2 files changed

+55
-48
lines changed

src/controllers/RemoteConfigController.js

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -160,43 +160,45 @@ export class RemoteConfigController extends EventEmitter {
160160
}
161161
}
162162

163-
fetchConfig() {
164-
return fetch(CONFIG_URL)
165-
.then(resp => resp.text())
166-
.then(txt => JSON.parse(txt));
167-
}
168-
169163
updateState(state = {}) {
170164
const currentState = this.store.getState();
171165
this.store.updateState({ ...currentState, ...state });
172166
}
173167

174168
async _getConfig() {
175169
try {
176-
const {
177-
blacklist = [],
178-
whitelist = [],
179-
networks = DEFAULT_CONFIG.NETWORKS,
180-
network_config = DEFAULT_CONFIG.NETWORK_CONFIG,
181-
messages_config = DEFAULT_CONFIG.MESSAGES_CONFIG,
182-
idle = DEFAULT_CONFIG.IDLE,
183-
pack_config = DEFAULT_CONFIG.PACK_CONFIG,
184-
} = await this.fetchConfig();
185-
186-
this.updateState({
187-
blacklist,
188-
whitelist,
189-
config: {
190-
idle,
191-
networks,
192-
network_config,
193-
messages_config,
194-
pack_config,
195-
},
196-
status: STATUS.UPDATED,
197-
});
170+
const response = await fetch(CONFIG_URL);
171+
172+
if (response.ok) {
173+
const {
174+
blacklist = [],
175+
whitelist = [],
176+
networks = DEFAULT_CONFIG.NETWORKS,
177+
network_config = DEFAULT_CONFIG.NETWORK_CONFIG,
178+
messages_config = DEFAULT_CONFIG.MESSAGES_CONFIG,
179+
idle = DEFAULT_CONFIG.IDLE,
180+
pack_config = DEFAULT_CONFIG.PACK_CONFIG,
181+
} = await response.json();
182+
183+
this.updateState({
184+
blacklist,
185+
whitelist,
186+
config: {
187+
idle,
188+
networks,
189+
network_config,
190+
messages_config,
191+
pack_config,
192+
},
193+
status: STATUS.UPDATED,
194+
});
195+
} else if (response.status < 500) {
196+
throw new Error(await response.text());
197+
}
198198
} catch (e) {
199199
this.updateState({ status: STATUS.ERROR });
200+
201+
throw new Error(`Could not fetch waves_keeper_blacklist.json: ${e}`);
200202
}
201203

202204
extension.alarms.create('updateConfig', {
@@ -208,23 +210,21 @@ export class RemoteConfigController extends EventEmitter {
208210
const { ignoreErrorsConfig } = this.store.getState();
209211

210212
try {
211-
const ignoreErrorsConfigResponse = await fetch(
212-
IGNORE_ERRORS_CONFIG_URL
213-
).then(resp =>
214-
resp.ok
215-
? resp.json()
216-
: resp.text().then(text => Promise.reject(new Error(text)))
217-
);
218-
219-
this.store.updateState({
220-
ignoreErrorsConfig: Object.assign(
221-
{},
222-
ignoreErrorsConfig,
223-
ignoreErrorsConfigResponse
224-
),
225-
});
213+
const response = await fetch(IGNORE_ERRORS_CONFIG_URL);
214+
215+
if (response.ok) {
216+
this.store.updateState({
217+
ignoreErrorsConfig: Object.assign(
218+
{},
219+
ignoreErrorsConfig,
220+
await response.json()
221+
),
222+
});
223+
} else if (response.status < 500) {
224+
throw new Error(await response.text());
225+
}
226226
} catch (err) {
227-
// ignore
227+
throw new Error(`Could not fetch keeper-ignore-errors.json: ${err}`);
228228
} finally {
229229
extension.alarms.create('updateIgnoreErrorsConfig', {
230230
delayInMinutes: IGNORE_ERRORS_CONFIG_UPDATE_INTERVAL,
@@ -303,11 +303,15 @@ export class RemoteConfigController extends EventEmitter {
303303

304304
async _fetchFeeConfig() {
305305
try {
306-
const feeConfig = await fetch(DEFAULT_FEE_CONFIG_URL).then(res =>
307-
res.json()
308-
);
306+
const response = await fetch(DEFAULT_FEE_CONFIG_URL);
309307

310-
this.store.updateState({ feeConfig });
308+
if (response.ok) {
309+
this.store.updateState({ feeConfig: await response.json() });
310+
} else if (response.status < 500) {
311+
throw new Error(await response.text());
312+
}
313+
} catch (err) {
314+
throw new Error(`Could not fetch fee.json: ${err}`);
311315
} finally {
312316
extension.alarms.create('fetchFeeConfig', {
313317
delayInMinutes: FEE_CONFIG_UPDATE_INTERVAL,

src/lib/localStore.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ export default class ExtensionStore {
257257
async _migrateFlatState() {
258258
const storageState = extension.storage.local;
259259

260+
// this should potentially fix FILE_ERROR_NO_SPACE error
261+
await this._remove(storageState, ['AssetInfoController']);
262+
260263
const state = await this._get(storageState);
261264
const migrateFields = CONTROLLERS.filter(controller => state[controller]);
262265

0 commit comments

Comments
 (0)