Skip to content

Commit

Permalink
Merge pull request #22 from dnowacki-usgs/longdaterange
Browse files Browse the repository at this point in the history
Catch error for long (2+ year) date requests, after CI stuff was fixed, this small update is good to go.
  • Loading branch information
joeyoun9 authored Aug 21, 2017
2 parents 85a8a1f + 4eed368 commit fd1b006
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion MesoPy.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ def _get_response(self, endpoint, request_dict):
"""
http_error = 'Could not connect to the API. This could be because you have no internet connection, a parameter' \
' was input incorrectly, or the API is currently down. Please try again.'

json_error = 'Could not retrieve JSON values. Try again with a shorter date range.'

# For python 3.4
try:
qsp = urllib.parse.urlencode(request_dict, doseq=True)
Expand All @@ -159,7 +162,13 @@ def _get_response(self, endpoint, request_dict):
raise MesoPyError(http_error)
except urllib.error.URLError:
raise MesoPyError(http_error)
return self._checkresponse(json.loads(resp.decode('utf-8')))

try:
json_data = json.loads(resp.decode('utf-8'))
except ValueError:
raise MesoPyError(json_error)

return self._checkresponse(json_data)

def _check_geo_param(self, arg_list):
r""" Checks each function call to make sure that the user has provided at least one of the following geographic
Expand Down

0 comments on commit fd1b006

Please sign in to comment.