mirror of
https://github.com/oceanprotocol/commons.git
synced 2023-03-15 18:03:00 +01:00
better error handling
This commit is contained in:
parent
aef52f61c0
commit
dc0f5c803d
@ -24,18 +24,14 @@ export default function useIpfsApi(config: IpfsConfig) {
|
||||
ipfsMessage = 'Checking IPFS gateway...'
|
||||
|
||||
try {
|
||||
const message = `Connected to ${config.host}`
|
||||
console.time(message)
|
||||
ipfs = await ipfsClient(config)
|
||||
console.timeEnd(message)
|
||||
ipfsMessage = message
|
||||
|
||||
const version = await ipfs.version()
|
||||
ipfsVersion = version.version
|
||||
ipfsMessage = `Connected to ${config.host}`
|
||||
} catch (error) {
|
||||
setIpfsError(error.message)
|
||||
setIpfsError(`IPFS connection error: ${error.message}`)
|
||||
}
|
||||
setIpfsReady(Boolean(ipfs))
|
||||
setIpfsReady(Boolean(await ipfs.id()))
|
||||
}
|
||||
|
||||
initIpfs()
|
||||
|
@ -15,5 +15,5 @@ export default function Status({
|
||||
: error
|
||||
? styles.error
|
||||
: styles.message
|
||||
return <div className={classes}>{message}</div>
|
||||
return <div className={classes}>{error || message}</div>
|
||||
}
|
||||
|
@ -75,10 +75,10 @@ export default function Ipfs({ addFile }: { addFile(url: string): void }) {
|
||||
const url = `ipfs://${cid}/${path}`
|
||||
|
||||
setMessage('Checking IPFS gateway URL')
|
||||
await pingUrl(urlGateway)
|
||||
|
||||
const isAvailable = await pingUrl(urlGateway)
|
||||
// add IPFS url to file.url
|
||||
addFile(url)
|
||||
isAvailable && addFile(url)
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -21,10 +21,11 @@ export async function pingUrl(url: string) {
|
||||
if (response.status !== 200) console.error(`Not found: ${url}`)
|
||||
|
||||
console.log(`File found: ${url}`)
|
||||
return
|
||||
return true
|
||||
} catch (error) {
|
||||
console.error(error.message)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
export function readFileAsync(file: File) {
|
||||
|
Loading…
Reference in New Issue
Block a user