Skip to content

Commit

Permalink
fix: safer logic when fetching profiles, #322
Browse files Browse the repository at this point in the history
  • Loading branch information
hstove committed Apr 30, 2020
1 parent 4927b72 commit e0a67fd
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/keychain/src/profiles.ts
Expand Up @@ -156,9 +156,15 @@ export const fetchProfile = async ({ identity, gaiaUrl }: { identity: Identity;
try {
const url = await identity.profileUrl(gaiaUrl);
const res = await fetch(url);
const json = await res.json();
const { decodedToken } = json[0];
return decodedToken.payload?.claim as Profile;
if (res.ok) {
const json = await res.json();
const { decodedToken } = json[0];
return decodedToken.payload?.claim as Profile;
}
if (res.status === 404) {
return null;
}
throw new Error('Network error when fetching profile');
} catch (error) {
return null;
}
Expand Down

0 comments on commit e0a67fd

Please sign in to comment.