From abf5dfa361ed3886b184c997fb88a22ea4e73c29 Mon Sep 17 00:00:00 2001 From: Klaus Sinani Date: Thu, 21 Mar 2019 19:56:45 +0200 Subject: [PATCH] Handle case where no release data is available. Fixes #3 (#4) --- src/rels.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/rels.js b/src/rels.js index 9f3c13e..a3468d5 100644 --- a/src/rels.js +++ b/src/rels.js @@ -221,30 +221,31 @@ class Rels { }); } - _getAll(repo) { - return this._get(this._path.releases(repo)); - } + async _getReleaseData(repo) { + const total = await this._get(this._path.releases(repo)); + + if (Array.isArray(total) && total.length === 0) { + throw new Error(`No available release data for the ${repo} repository`); + } + + const latest = await this._get(this._path.latest(repo)); - _getLatest(repo) { - return this._get(this._path.latest(repo)); + return [total, latest]; } async init(repo, n) { - let [data, latest] = []; + let [total, latest] = []; try { - [data, latest] = await Promise.all([ - this._getAll(repo), - this._getLatest(repo) - ]); + [total, latest] = await this._getReleaseData(repo); } catch (error) { return fatal(error); } this._latestRelease = Object.assign({}, latest); - [data, n] = [this._formatData(data), this._format.listN(n)]; + [total, n] = [this._formatData(total), this._format.listN(n)]; - this._display(repo, data, n); + this._display(repo, total, n); } }