Skip to content

Commit

Permalink
added api request timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredfrancis committed May 12, 2018
1 parent 2436181 commit 25e3258
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/endpoint/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def api():
parameters, isJson)
except Exception as e:
app.logger.warn("API call failed", e)
result_json["speechResponse"] = ["Service is not available. "]
result_json["speechResponse"] = ["Service is not available. Please try again later."]
else:
context["result"] = result
template = Template(
Expand Down
12 changes: 6 additions & 6 deletions app/endpoint/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ def call_api(url, type,headers={}, parameters = {}, is_json=False):
"""
app.logger.info("Initiating API Call with following info: url => {} payload => {}".format(url,parameters))
if "GET" in type:
response = requests.get(url,headers=headers, params=parameters)
response = requests.get(url,headers=headers, params=parameters, timeout=5)
elif "POST" in type:
if is_json:
response = requests.post(url,headers=headers, json=parameters)
response = requests.post(url,headers=headers, json=parameters, timeout=5)
else:
response = requests.post(url,headers=headers, params=parameters)
response = requests.post(url,headers=headers, params=parameters, timeout=5)
elif "PUT" in type:
if is_json:
response = requests.put(url,headers=headers, json=parameters)
response = requests.put(url,headers=headers, json=parameters, timeout=5)
else:
response = requests.put(url,headers=headers, params=parameters)
response = requests.put(url,headers=headers, params=parameters, timeout=5)
elif "DELETE" in type:
response = requests.delete(url,headers=headers, params=parameters)
response = requests.delete(url,headers=headers, params=parameters, timeout=5)
else:
raise Exception("unsupported request method.")
result = json.loads(response.text)
Expand Down

0 comments on commit 25e3258

Please sign in to comment.