Skip to content

Conversation

@rzats
Copy link
Contributor

@rzats rzats commented Oct 11, 2024

Closes #45.

In the Import Dataset dialogue, displays the errors from the EpiData API to the user if one is present:

Screenshot 2024-10-11 at 17 03 30

@rzats rzats requested a review from melange396 October 11, 2024 14:04
const data = loadEpidata(title, res, columns, columnRenamings, { _endpoint: endpoint, ...params });
if (data.datasets.length == 0) {
try {
const data = loadEpidata(title, res, columns, columnRenamings, { _endpoint: endpoint, ...params });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we put the try block around just this loadEpidata() line? if the other lines are throwing exceptions, we should handle them in a different way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is already the case? The try block is around three lines:

const data = loadEpidata(...)
if (data.datasets.length == 0) {...}
return data;

And the last two can't really error out.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thats what im saying -- the try scope should contain only the line(s) where we anticipate a possible exception

`
<div class="uk-alert uk-alert-error">
<a href="${url.href}">API Link</a> returned no data.
Failed to fetch API data from <a href="${url.href}">API Link</a>.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add more information to this, like the returned status code at the very least? when a user runs into the rate limiting, this will be helpful. in fact, when a 429 is served via the API, it returns this html in the body, which would be even more useful to a user:

<!doctype html>
<html lang=en>
<title>429 Too Many Requests</title>
<h1>Too Many Requests</h1>
<p>Rate limit exceeded for anonymous queries. To remove this limit, register a free API key at https://api.delphi.cmu.edu/epidata/admin/registration_form</p>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also fixed - it should now include the error code if it's not inside the JSON.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isnt working for me when it encounters a 429 from making too many requests... it still just says "Failed to fetch API data from API Link."

@rzats rzats requested a review from melange396 November 21, 2024 18:48
@melange396
Copy link
Contributor

Still showing no error detail when rate limit has been exceeded:
image

Copy link
Contributor

@melange396 melange396 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, this shows the error message that accompanies the 429 response now:
image

a couple things to neaten up and i think this is done... also, should we wait until #83 is fixed before merging?

Comment on lines +61 to +63
return fetch(url.toString(), fetchOptions).then((d) => {
return processResponse(d);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this work (or something similar)?

Suggested change
return fetch(url.toString(), fetchOptions).then((d) => {
return processResponse(d);
});
return fetch(url.toString(), fetchOptions).then(processResponse);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explored in #86

.alert(
`
<div class="uk-alert uk-alert-error">
Failed to fetch API data from <a href="${url.href}">API Link</a>:<br/><i>${res['message']}</i>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make the three versions of this message ever-so-slightly different (for ease of future debugging)?

Suggested change
Failed to fetch API data from <a href="${url.href}">API Link</a>:<br/><i>${res['message']}</i>
Failed to fetch API data from <a href="${url.href}">API Link</a>: (code f01)<br/><i>${res['message']}</i>

@melange396 melange396 merged commit d3f935a into dev Feb 6, 2025
7 checks passed
@melange396 melange396 deleted the rzatserkovnyi/improve-errors branch February 6, 2025 20:36
@melange396 melange396 mentioned this pull request Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve behavior on errors when importing a dataset

3 participants