DoSomething / legacy-website

:moyai: The DoSomething.org legacy website.
https://www.dosomething.org/
MIT License
50 stars 22 forks source link

API returns invalid JSON if count is large enough #6315

Open aaronschachter opened 8 years ago

aaronschachter commented 8 years ago

BUG

Current Behavior

https://northstar.dosomething.org/v1/signups?user=56eab76e469c6444628b60f2&count=150 no json 4 u

Desired Behavior

This is definitely an edge case for now, but may bite us as our users signup and reportback for multiple campaigns/runs as we focus on increasing impact. We're currently querying for 200 signups in iOS as a hack until we add paginated API requests when displaying a User's Profile.

I'd imagine (but haven't tested) that this is an issue across all Phoenix API endpoints, not just Signups. We could ballpark a max count to request, but in theory, if it's just truncating the response after some number of bytes, as @DFurnes wondered in #api Slack, we could inspect the size of our response before returning -- and instead return an error object.

DFurnes commented 8 years ago

Interestingly, I'm not getting this issue when making the same request against Phoenix on my local so it might be hard to debug exactly what's going wrong with this on production.

It does return a whopping 115kb of JSON though, which seems pretty outrageous. I think a good solution would be to cap the count parameter to a reasonable limit (say, 50?) and then have clients request additional pages of results when needed.