Dont try to download files that dont exist on sourcify
This commit is contained in:
parent
a2c2403d05
commit
731a8190ed
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue