refactor: enhance error message of promise reject
This commit is contained in:
parent
ab1914bc1a
commit
947ed8e60f
3 changed files with 7 additions and 7 deletions
|
|
@ -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}`);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue