refactor: enhance error message of promise reject

This commit is contained in:
peaceiris 2019-09-18 03:15:02 +09:00
parent ab1914bc1a
commit 947ed8e60f
3 changed files with 7 additions and 7 deletions

View file

@ -6,14 +6,13 @@ function getLatestVersion() {
const url = "https://formulae.brew.sh/api/formula/hugo.json";
xhr.open("GET", url);
xhr.send();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
const result = JSON.parse(xhr.responseText);
const latestVersion = result.versions.stable;
resolve(latestVersion);
} else if (xhr.readyState === 4 && xhr.status !== 200) {
reject(`ERROR: got status ${xhr.status}`);
reject(`ERROR: got status ${xhr.status} of ${url}`);
}
};
});