Skip to content

Commit

Permalink
Timeout handling for gateway (#259)
Browse files Browse the repository at this point in the history
Timeout handling for gateway
  • Loading branch information
piyushroshan authored Jul 2, 2024
1 parent 09623fc commit 824a1ff
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions services/workshop/crapi/shop/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,24 +137,28 @@ def get(self, request, order_id=None, user=None):
data["user"] = user_dict
data["order"] = order_serializer.data
data["amount"] = float(order.product.price) * int(order.quantity)
payment_response = requests.post(
gateway_endpoint,
headers={
"Authorization": gateway_credential,
"Content-Type": "application/json",
},
json=data,
verify=False,
)
if payment_response.status_code == 200:
payment = payment_response.json()
else:
logging.error(
"Payment response error, {}: {}".format(
payment_response.status_code, payment_response.content
)
try:
payment_response = requests.post(
gateway_endpoint,
headers={
"Authorization": gateway_credential,
"Content-Type": "application/json",
},
json=data,
verify=False,
timeout=5,
)
logging.debug("payment response: {}".format(payment))
if payment_response.status_code == 200:
payment = payment_response.json()
else:
logging.error(
"Payment response error, {}: {}".format(
payment_response.status_code, payment_response.content
)
)
logging.debug("payment response: {}".format(payment))
except Exception as e:
logging.error(e, exc_info=True)
except Exception as e:
logging.error(e, exc_info=True)
response_data = dict(order=order_serializer.data, payment=payment)
Expand Down

0 comments on commit 824a1ff

Please sign in to comment.