Npe fix

Hello,
This pull request will fix some error cases when the response does not map to JSON and ends up causing a NullPointerException.