Skip to content

Commit

Permalink
Detect and handle errors fetching the latest version (#60)
Browse files Browse the repository at this point in the history
* Detect and handle errors fetching the latest version

This attempts to detect such errors, assuming that they appear with
suitable HTTP status codes, and raises useful errors for them.

Fixes #59

* Make a trivial change to trigger workflows

* Undo trivial change

---------

Co-authored-by: Helio Machado <[email protected]>
  • Loading branch information
PeterJCLaw and 0x2b3bfa0 authored Apr 4, 2024
1 parent d549770 commit 34fbdc6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

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 34fbdc6

Please sign in to comment.