feat: show score not in dataset error

This commit is contained in:
Xmader 2020-11-24 04:12:31 -05:00
parent 92619ab3f7
commit 195f607817
No known key found for this signature in database
GPG key ID: A20B97FB9EB730E4
2 changed files with 16 additions and 3 deletions

View file

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

View file

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