From 195f6078176611943d4c961974ac0fbab2d9aef1 Mon Sep 17 00:00:00 2001 From: Xmader Date: Tue, 24 Nov 2020 04:12:31 -0500 Subject: [PATCH] feat: show `score not in dataset` error --- src/mscz.ts | 7 ++++++- src/scoreinfo.ts | 12 ++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/mscz.ts b/src/mscz.ts index 7781ff1..0ef500c 100644 --- a/src/mscz.ts +++ b/src/mscz.ts @@ -11,8 +11,13 @@ export const fetchMscz = async (scoreinfo: ScoreInfo, _fetch = fetch): Promise => { const r0 = await _fetch(url) - assertRes(r0) + // 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() diff --git a/src/scoreinfo.ts b/src/scoreinfo.ts index 887ef5e..d714070 100644 --- a/src/scoreinfo.ts +++ b/src/scoreinfo.ts @@ -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}` } }