From 0b5dc2d29018efe9367cb6f0fdda592434dd27bc Mon Sep 17 00:00:00 2001 From: Martti Malmi Date: Fri, 6 Oct 2023 10:19:47 +0300 Subject: [PATCH] proper error handling in profile http cache --- packages/system-react/src/useUserProfile.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/system-react/src/useUserProfile.ts b/packages/system-react/src/useUserProfile.ts index a06c0575..d6b12585 100644 --- a/packages/system-react/src/useUserProfile.ts +++ b/packages/system-react/src/useUserProfile.ts @@ -12,18 +12,22 @@ export function useUserProfile(pubKey?: HexKey): MetadataCache | undefined { if (pubKey) { system.ProfileLoader.TrackMetadata(pubKey); if (process.env.HTTP_CACHE && !system.ProfileLoader.Cache.getFromCache(pubKey)) { - try { - fetch(`${process.env.HTTP_CACHE}/profile/${pubKey}`).then(async r => { + fetch(`${process.env.HTTP_CACHE}/profile/${pubKey}`) + .then(async r => { if (r.ok) { - const data = await r.json(); - if (data) { - system.ProfileLoader.onProfileEvent(data); + try { + const data = await r.json(); + if (data) { + system.ProfileLoader.onProfileEvent(data); + } + } catch (e) { + console.error(e); } } + }) + .catch(e => { + console.error(e); }); - } catch (e) { - console.error(e); - } } } const release = system.ProfileLoader.Cache.hook(h, pubKey);