Skip to content

Commit abe9249

Browse files
committed
api: add error handling for GetChanInfo and GetNodeInfo calls
1 parent 6c16b59 commit abe9249

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

app/src/__tests__/util/appStorage.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import AppStorage from 'util/appStorage';
22

3-
jest.unmock('util/appStorage');
4-
53
describe('appStorage util', () => {
64
const key = 'test-data';
75
const settings = {

app/src/util/appStorage.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,23 @@ export default class AppStorage {
8181

8282
// if there are any keys that are not in the cache
8383
if (keys.length) {
84-
// call the API to get the missing data
85-
data = await fetchFromApi(keys, data);
84+
try {
85+
// call the API to get the missing data
86+
data = await fetchFromApi(keys, data);
8687

87-
// update the expiration date only if it has expired. this ensures
88-
// that data will remain in the cache for up to the timeout
89-
const expires =
90-
cached && cached.expires > Date.now()
91-
? cached.expires
92-
: Date.now() + CACHE_TIMEOUT;
88+
// update the expiration date only if it has expired. this ensures
89+
// that data will remain in the cache for up to the timeout
90+
const expires =
91+
cached && cached.expires > Date.now()
92+
? cached.expires
93+
: Date.now() + CACHE_TIMEOUT;
9394

94-
// update localStorage with the new data
95-
this.set(cacheKey, { expires, data });
96-
log.info(`updated cache with ${keys.length} new ${cacheKey}`);
95+
// update localStorage with the new data
96+
this.set(cacheKey, { expires, data });
97+
log.info(`updated cache with ${keys.length} new ${cacheKey}`);
98+
} catch (error) {
99+
log.error(`failed to fetch ${cacheKey} from the API`, error.message);
100+
}
97101
}
98102

99103
return data;

0 commit comments

Comments
 (0)