1
0
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:
Matthias Kretschmann 2019-10-09 17:32:40 +02:00
parent aef52f61c0
commit dc0f5c803d
Signed by: m
GPG Key ID: 606EEEF3C479A91F
4 changed files with 8 additions and 11 deletions

View File

@ -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()

View File

@ -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>
}

View File

@ -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 (

View File

@ -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) {