Dont try to download files that dont exist on sourcify

This commit is contained in:
Willian Mitsuda 2022-08-10 02:04:36 -03:00
parent a2c2403d05
commit 731a8190ed
No known key found for this signature in database
1 changed files with 10 additions and 16 deletions

View File

@ -81,24 +81,17 @@ export type Metadata = {
}; };
}; };
const fetchSourcifyMetadata = async ( const sourcifyFetcher = async (url: string) => {
address: ChecksummedAddress,
chainId: number,
source: SourcifySource,
abortController: AbortController
): Promise<Metadata | null> => {
try { try {
const metadataURL = sourcifyMetadata(address, chainId, source); const res = await fetch(url);
const result = await fetch(metadataURL, { if (res.ok) {
signal: abortController.signal, return res.json();
});
if (result.ok) {
return await result.json();
} }
return null; return null;
} catch (err) { } catch (err) {
console.error(err); console.warn(
`error while getting Sourcify metadata: url=${url} err=${err}`
);
return null; return null;
} }
}; };
@ -112,8 +105,9 @@ export const useSourcifyMetadata = (
address === undefined || chainId === undefined address === undefined || chainId === undefined
? null ? null
: sourcifyMetadata(address, chainId, source); : sourcifyMetadata(address, chainId, source);
const { data, error } = useSWRImmutable<Metadata>(metadataURL, (url) => const { data, error } = useSWRImmutable<Metadata>(
fetch(url).then((res) => res.json()) metadataURL,
sourcifyFetcher
); );
if (error) { if (error) {
return null; return null;