Skip to content

Commit

Permalink
Detect and handle errors fetching the latest version
Browse files Browse the repository at this point in the history
This attempts to detect such errors, assuming that they appear with
suitable HTTP status codes, and raises useful errors for them.

Fixes iterative#59
  • Loading branch information
PeterJCLaw committed Feb 1, 2024
1 parent d549770 commit e564f07
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ const download = async (url, path) => {
const getLatestVersion = async () => {
const endpoint = 'https://updater.dvc.org';
const response = await fetch(endpoint, { method: 'GET' });
const { version } = await response.json();

return version;
if (response.ok) {
const { version } = await response.json();
return version;
} else {
const status = `Status: ${response.status} ${response.statusText}`;
const body = `Body:\n${await response.text()}`;
throw new Error(`${status}\n${body}`);
}
};

const prepGitRepo = async () => {
Expand Down

0 comments on commit e564f07

Please sign in to comment.