Countly/countly-server — pull request #92 by PUDRESCU (2014-04-30 23:32:32+00:00)
Title: respond with 400 if events or metrics JSON data is not properly formatted

Use Case: Every now and then (been fairly difficult for us to reproduce) the iOS SDK sends improperly formatted JSON data in the events parameter.

example: ```/i?app_key=key&device_id=id×tamp=1398821482&events=[{"key":"eventKey","count":1,"segmentation":{"ProductIds":}]```

We were tipped off to this by funny data in our mongoDB collections
```{"2014": {
"": {
"c": 31
} ...```
where one would expect the day or month instead of an empty parameter. We saw a similar request to the above query string in our nginx logs during testing. Following the api code path it seems that the try catch blocks surrounding the JSON.parse calls really just swallow the exception and don't do anything about it, allowing the request to make it through to the data access layer. So I'm proposing a 400 response immediately after a bad JSON.parse