Added error handling for invalid json responses

I'm not sure if such errors are caused by the API being overloaded, if
so then we'll keep this, otherwise it's wasted effort to retry something
which will fail again always.