mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
api: add error handling for GetChanInfo and GetNodeInfo calls
This commit is contained in:
parent
6c16b59a7b
commit
abe9249613
2 changed files with 15 additions and 13 deletions
|
|
@ -1,7 +1,5 @@
|
|||
import AppStorage from 'util/appStorage';
|
||||
|
||||
jest.unmock('util/appStorage');
|
||||
|
||||
describe('appStorage util', () => {
|
||||
const key = 'test-data';
|
||||
const settings = {
|
||||
|
|
|
|||
|
|
@ -81,19 +81,23 @@ export default class AppStorage {
|
|||
|
||||
// if there are any keys that are not in the cache
|
||||
if (keys.length) {
|
||||
// call the API to get the missing data
|
||||
data = await fetchFromApi(keys, data);
|
||||
try {
|
||||
// call the API to get the missing data
|
||||
data = await fetchFromApi(keys, data);
|
||||
|
||||
// update the expiration date only if it has expired. this ensures
|
||||
// that data will remain in the cache for up to the timeout
|
||||
const expires =
|
||||
cached && cached.expires > Date.now()
|
||||
? cached.expires
|
||||
: Date.now() + CACHE_TIMEOUT;
|
||||
// update the expiration date only if it has expired. this ensures
|
||||
// that data will remain in the cache for up to the timeout
|
||||
const expires =
|
||||
cached && cached.expires > Date.now()
|
||||
? cached.expires
|
||||
: Date.now() + CACHE_TIMEOUT;
|
||||
|
||||
// update localStorage with the new data
|
||||
this.set(cacheKey, { expires, data });
|
||||
log.info(`updated cache with ${keys.length} new ${cacheKey}`);
|
||||
// update localStorage with the new data
|
||||
this.set(cacheKey, { expires, data });
|
||||
log.info(`updated cache with ${keys.length} new ${cacheKey}`);
|
||||
} catch (error) {
|
||||
log.error(`failed to fetch ${cacheKey} from the API`, error.message);
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue