feat: show score not in dataset
error
This commit is contained in:
parent
92619ab3f7
commit
195f607817
2 changed files with 16 additions and 3 deletions
|
@ -11,8 +11,13 @@ export const fetchMscz = async (scoreinfo: ScoreInfo, _fetch = fetch): Promise<A
|
|||
const url = scoreinfo.msczCidUrl
|
||||
msczBufferP = (async (): Promise<ArrayBuffer> => {
|
||||
const r0 = await _fetch(url)
|
||||
// ipfs-http-gateway specific error
|
||||
// may read further error msg as json
|
||||
if (r0.status !== 500) {
|
||||
assertRes(r0)
|
||||
}
|
||||
const cidRes = await r0.json()
|
||||
|
||||
const r = await _fetch(scoreinfo.getMsczUrl(cidRes))
|
||||
assertRes(r)
|
||||
const data = await r.arrayBuffer()
|
||||
|
|
|
@ -24,9 +24,17 @@ export abstract class ScoreInfo {
|
|||
return `https://ipfs.infura.io:5001/api/v0/block/stat?arg=${this.msczIpfsRef}`
|
||||
}
|
||||
|
||||
getMsczUrl (cidRes: { Key: string }): string {
|
||||
getMsczUrl (cidRes: { Key: string; Message: string }): string {
|
||||
const cid = cidRes.Key
|
||||
if (!cid) throw new Error('score not in dataset')
|
||||
if (!cid) {
|
||||
// read further error msg
|
||||
const err = cidRes.Message
|
||||
if (err.includes('no link named')) { // file not found
|
||||
throw new Error('score not in dataset')
|
||||
} else {
|
||||
throw new Error(err)
|
||||
}
|
||||
}
|
||||
return `https://ipfs.infura.io/ipfs/${cid}`
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue