Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when API request is made for an invalid region? #1365

Open
nmdefries opened this issue Jan 4, 2024 · 1 comment
Open

Error when API request is made for an invalid region? #1365

nmdefries opened this issue Jan 4, 2024 · 1 comment
Labels
api change affect the API and its responses enhancement

Comments

@nmdefries
Copy link
Contributor

nmdefries commented Jan 4, 2024

Instead of handling region-checking on the interface client side, can we handle it here?

When i try region = "taiwan" with both ecdc_ili (Europe) and kcdc_ili (Korea) through epidatr, I get epidata warning: no results and an empty tibble. But I'm pretty sure that this region is invalid. It seems like this query should error instead of returning an empty result, which implies that the query was valid

Ideally the error would say that the requested region is invalid, with more info about how to provide a valid region name.

covidcast does error with invalid geo_values, although the error is sub-optimal (this is with an API key set).

> covidcast::covidcast_signal("jhu-csse", "confirmed_cumulative_num", geo_type = "state", geo_values = "zz")
Error in .request("covidcast", params) : 
  Bad Request (HTTP 400). Failed to fetch data from API anonymously.
@nmdefries nmdefries added enhancement api change affect the API and its responses labels Jan 4, 2024
@melange396
Copy link
Collaborator

(I'm not sure what you mean by "interface side", and i would guess you mean "client side", but i also suppose it doesn't actually matter for this...)

The covidcast endpoint is easily the most full-featured and complex of all our endpoints. It uses delphi_utils.GeoMapper to identify [il]legitimate locations, and it does some other input validation for other fields too. On the other hand, ecdc_ili and kcdc_ili are much "leaner" endpoints that don't do much more than translate an http request to a database query. That doesn't mean they can't be augmented to validate their inputs too, but its not a simple drop-in replacement especially because GeoMapper will not cover European or Asian locations.

For what its worth, your example invalid-geo covidcast request would've gotten this reply from the covidcast api web server:

{"epidata": [], "message": "Invalid geo_value(s) zz for the requested geo_type state", "result": -1}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api change affect the API and its responses enhancement
Projects
None yet
Development

No branches or pull requests

2 participants