codeforamerica / cfapi

The Code for America API. Tracks and motivates activity and participation across the civic technology movement.
http://codeforamerica.org/api
MIT License
113 stars 52 forks source link

Handle empty body from Meetup API response #318

Closed tdooner closed 6 years ago

tdooner commented 6 years ago

The Meetup API occasionally returns an empty response for a valid request that should return JSON. Since an empty string cannot be parsed as valid JSON, this causes an error and crashes the updating process.

I opened a support ticket about this a month ago but they don't seem to have made any progress figuring this out.

It is very easy to reproduce by looking at the response size:

while :; do
  curl -s https://api.meetup.com/2/groups\?group_urlname\=Code-for-Greenville\&key\=$MEETUP_KEY | wc -c;
done

which returns for me:

       0
    3120
    3120
    3120
    3120
    3120
    3120
    3120
    3120
    3120
    3120
    3120
    3120
    3120
    3120
    3120
    3120
    3120
    3120
       0
    3120
    3120
    3120
    3120
    3120
    3120
    3120
    3120
    3120
    3120
    3120
    3120
    3120
    3120
       0
    3120
    3120

If this method returns None, the calling method will not overwrite any value that exists in the column. So, over time, we will get accurate membership information still, even if not for a specific run.

Regression test included!