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...'
|
ipfsMessage = 'Checking IPFS gateway...'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const message = `Connected to ${config.host}`
|
|
||||||
console.time(message)
|
|
||||||
ipfs = await ipfsClient(config)
|
ipfs = await ipfsClient(config)
|
||||||
console.timeEnd(message)
|
|
||||||
ipfsMessage = message
|
|
||||||
|
|
||||||
const version = await ipfs.version()
|
const version = await ipfs.version()
|
||||||
ipfsVersion = version.version
|
ipfsVersion = version.version
|
||||||
|
ipfsMessage = `Connected to ${config.host}`
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setIpfsError(error.message)
|
setIpfsError(`IPFS connection error: ${error.message}`)
|
||||||
}
|
}
|
||||||
setIpfsReady(Boolean(ipfs))
|
setIpfsReady(Boolean(await ipfs.id()))
|
||||||
}
|
}
|
||||||
|
|
||||||
initIpfs()
|
initIpfs()
|
||||||
|
@ -15,5 +15,5 @@ export default function Status({
|
|||||||
: error
|
: error
|
||||||
? styles.error
|
? styles.error
|
||||||
: styles.message
|
: 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}`
|
const url = `ipfs://${cid}/${path}`
|
||||||
|
|
||||||
setMessage('Checking IPFS gateway URL')
|
setMessage('Checking IPFS gateway URL')
|
||||||
await pingUrl(urlGateway)
|
|
||||||
|
|
||||||
|
const isAvailable = await pingUrl(urlGateway)
|
||||||
// add IPFS url to file.url
|
// add IPFS url to file.url
|
||||||
addFile(url)
|
isAvailable && addFile(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -21,10 +21,11 @@ export async function pingUrl(url: string) {
|
|||||||
if (response.status !== 200) console.error(`Not found: ${url}`)
|
if (response.status !== 200) console.error(`Not found: ${url}`)
|
||||||
|
|
||||||
console.log(`File found: ${url}`)
|
console.log(`File found: ${url}`)
|
||||||
return
|
return true
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error.message)
|
console.error(error.message)
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
export function readFileAsync(file: File) {
|
export function readFileAsync(file: File) {
|
||||||
|
Loading…
Reference in New Issue
Block a user