Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
fix: catch exception when lease status is unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
jtary committed Oct 2, 2023
1 parent f1b390e commit 7f76e3a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
20 changes: 12 additions & 8 deletions web/src/hooks/useDeploymentData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ export default function useDeploymentData(owner: string) {
// monkey patch the leaseId to avoid [object Object]
lease.leaseId.dseq = Long.fromValue(lease.leaseId.dseq);

return providerUrl && queryLeaseStatus(LeaseID.toJSON(lease.leaseId) as any, providerUrl);
try {
return providerUrl && queryLeaseStatus(LeaseID.toJSON(lease.leaseId) as any, providerUrl);
} catch (e) {
console.warn('Unable to fetch lease status', e);
}
}
},
[certificate]
Expand Down Expand Up @@ -131,12 +135,12 @@ export default function useDeploymentData(owner: string) {
}

if (query.deployment?.state === 1) {
const status = await getLeaseStatus(lease);
try {
const status = await getLeaseStatus(lease);

if (status === undefined || status === '') {
console.warn('Unable to resolve lease status for deployment:', dseq);
} else {
try {
if (status === undefined || status === '') {
console.warn('Unable to resolve lease status for deployment:', dseq);
} else {
const leaseStatus = await status.json() as any;

if (leaseStatus && leaseStatus.services) {
Expand All @@ -146,9 +150,9 @@ export default function useDeploymentData(owner: string) {
.map((uri) => uri[0])
.join(', ');
}
} catch (e) {
console.warn('Unable to parse lease status', e);
}
} catch (e) {
console.warn('Unable to resolve lease status for deployment:', dseq);
}
}

Expand Down
6 changes: 5 additions & 1 deletion web/src/hooks/useLeaseStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ export function useLeaseStatus(lease: Lease) {
if (hostUri && leaseId && certificate.$type !== 'Invalid Certificate') {
return queryLeaseStatus(LeaseID.toJSON(leaseId) as any, hostUri)
.then(response => response.json())
.then(response => response as LeaseStatus);
.then(response => response as LeaseStatus)
.catch(err => {
console.warn('Error fetching lease status', err);
return undefined;
});
}

return Promise.reject('No lease status available');
Expand Down

0 comments on commit 7f76e3a

Please sign in to comment.