Skip to content

Commit

Permalink
[FIX] lcc_comchain_base: improve error management on pyc3l requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Stéphan Sainléger committed Oct 23, 2024
1 parent c4702c6 commit 2374c3b
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions lcc_comchain_base/models/wallet.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import json
import logging
import re
import time
from odoo import models, fields, api
from pyc3l.ApiHandling import APIError
from pyc3l import Pyc3l
from odoo.addons.lcc_lokavaluto_app_connection import tools

Expand Down Expand Up @@ -200,12 +202,34 @@ def credit_wallet(self, amount=0):
}

transaction = pyc3l.Transaction(response)
if transaction.data["recieved"] != round(amount * 100):

retry = 0
while True:
try:
received = transaction.data["recieved"]
break
except APIError as e:
if not e.args[0].startswith("API Call failed without message"):
_logger.error(tools.format_last_exception())
return {
"success": False,
"response": response,
"error": "Failure when trying to get transaction info: %s" % e,
}
retry += 1
if retry >= 10:
return {
"success": False,
"response": response,
"error": "Max retry reached to get transaction info (10 retries)",
}
time.sleep(0.5)
if received != round(amount * 100):
return {
"success": False,
"response": response,
"error": "Order sent, but checking transaction record returned as an unexepected amount of '%s' received."
% transaction.data["recieved"],
% received,
}

# All checks performed
Expand Down

0 comments on commit 2374c3b

Please sign in to comment.