Spaces:
Running
Running
fix fallback when trying insertion of already existing transaction
Browse files- src/main.py +4 -9
src/main.py
CHANGED
|
@@ -149,18 +149,13 @@ async def process_transaction(
|
|
| 149 |
try:
|
| 150 |
# Insert every single transaction into the database
|
| 151 |
transaction = insert_transaction(db, transaction)
|
| 152 |
-
except UniqueViolation:
|
| 153 |
-
logger.warning("Transaction
|
| 154 |
-
|
|
|
|
| 155 |
transaction_number=transaction.transaction_number,
|
| 156 |
db=db
|
| 157 |
)
|
| 158 |
-
except IntegrityError as e:
|
| 159 |
-
logger.error(e)
|
| 160 |
-
raise HTTPException(
|
| 161 |
-
status_code=HTTP_422_UNPROCESSABLE_ENTITY,
|
| 162 |
-
detail=f"Transaction {transaction.transaction_number} is not valid. Check input values."
|
| 163 |
-
)
|
| 164 |
except Exception as e:
|
| 165 |
logger.error(e)
|
| 166 |
raise HTTPException(
|
|
|
|
| 149 |
try:
|
| 150 |
# Insert every single transaction into the database
|
| 151 |
transaction = insert_transaction(db, transaction)
|
| 152 |
+
except (UniqueViolation, IntegrityError):
|
| 153 |
+
logger.warning("Transaction cannot be inserted in the database - checking existence...")
|
| 154 |
+
db.rollback()
|
| 155 |
+
return await get_fraud_status(
|
| 156 |
transaction_number=transaction.transaction_number,
|
| 157 |
db=db
|
| 158 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
except Exception as e:
|
| 160 |
logger.error(e)
|
| 161 |
raise HTTPException(
|