Exchange backend fix (#3253)

* Prevent creation of duplicate backend objects

* Ignore exchange errors, rather than returning None

* Revert "Prevent creation of duplicate backend objects"

This reverts commit 0b6d1ce86f.
This commit is contained in:
Oliver 2022-06-25 15:30:54 +10:00 committed by GitHub
parent 44b42050aa
commit ce67fd1c61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,8 +44,9 @@ class InvenTreeExchange(SimpleExchangeBackend):
response = urlopen(url, timeout=5, context=context)
return response.read()
except Exception:
# Returning None here will raise an error upstream
return None
# Something has gone wrong, but we can just try again next time
# Raise a TypeError so the outer function can handle this
raise TypeError
def update_rates(self, base_currency=None):
"""Set the requested currency codes and get rates."""
@ -60,6 +61,8 @@ class InvenTreeExchange(SimpleExchangeBackend):
# catch connection errors
except URLError:
print('Encountered connection error while updating')
except TypeError:
print('Exchange returned invalid response')
except OperationalError as e:
if 'SerializationFailure' in e.__cause__.__class__.__name__:
print('Serialization Failure while updating exchange rates')