adding error handling for api response

With the recent 504 errors this is a tiny change to prevent JSON::XS from puking on HTML