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

getJSON() call fails with 'unexpected end of file' error #4

Open
jschuur opened this issue Dec 28, 2020 · 1 comment
Open

getJSON() call fails with 'unexpected end of file' error #4

jschuur opened this issue Dec 28, 2020 · 1 comment

Comments

@jschuur
Copy link

jschuur commented Dec 28, 2020

While attempting to use this in Node (14.13.1 FWIW), I get the following error...

(node:92897) UnhandledPromiseRejectionWarning: Error: unexpected end of file
    at Zlib.zlibOnError [as onerror] (zlib.js:180:17)

...with the following code:

const Cov19API = require('@publichealthengland/uk-covid19').default;

(async () => {
  const casesAndDeaths = {
    date: 'date',
    areaName: 'areaName',
    areaCode: 'areaCode',
    newDeaths28DaysByDeathDate: 'newDeaths28DaysByDeathDate',
  };

  const englandOnly = ['areaType=nation', 'areaName=England'];

  const api = new Cov19API({
    filters: englandOnly,
    structure: casesAndDeaths,
  });

  const data = await api.getJSON();
  console.log(data);
})();

I've added .default per #1 and updated the metrics per #3 in this code already. I did add an await before api.getJSON(), since that returns a promise.

As best as I can tell from debugging this, the error seems to come from the axios call in this.head(), triggered at the end of getJSON, when the API returns status code 204. Wasn't able to solve the problem though.

As a workaround, calling getCSV doesn't have this problem (because it doesn't make a HEAD request).

@jschuur
Copy link
Author

jschuur commented Dec 28, 2020

This seems to be lead:

axios.head called on a .gz file throws an exception, presumably due to attempting to deflate a non-existent response body.

Not sure why it thinks the response is compressed though.

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

No branches or pull requests

1 participant