Skip to content

Commit

Permalink
Handle case where no release data is available. Fixes #3 (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
klaudiosinani authored Mar 21, 2019
1 parent ce3bc5a commit abf5dfa
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/rels.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit abf5dfa

Please sign in to comment.