fix: catch AssertionErrors
This commit is contained in:
parent
18196bf226
commit
9ce316debe
2 changed files with 91 additions and 6 deletions
|
|
@ -110,7 +110,7 @@ async def handle_order_paid(order_id: str, merchant_pubkey: str):
|
||||||
merchant = await get_merchant_by_pubkey(merchant_pubkey)
|
merchant = await get_merchant_by_pubkey(merchant_pubkey)
|
||||||
assert merchant, f"Merchant cannot be found for order {order_id}"
|
assert merchant, f"Merchant cannot be found for order {order_id}"
|
||||||
|
|
||||||
# lock
|
# todo: lock
|
||||||
success, message = await update_products_for_order(merchant, order)
|
success, message = await update_products_for_order(merchant, order)
|
||||||
await notify_client_of_order_status(order, merchant, success, message)
|
await notify_client_of_order_status(order, merchant, success, message)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
|
|
|
||||||
95
views_api.py
95
views_api.py
|
|
@ -137,6 +137,11 @@ async def api_delete_merchant(
|
||||||
|
|
||||||
await unsubscribe_from_direct_messages(merchant.public_key)
|
await unsubscribe_from_direct_messages(merchant.public_key)
|
||||||
await delete_merchant(merchant.id)
|
await delete_merchant(merchant.id)
|
||||||
|
except AssertionError as ex:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
|
detail=str(ex),
|
||||||
|
)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logger.warning(ex)
|
logger.warning(ex)
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
@ -154,6 +159,11 @@ async def api_get_zones(wallet: WalletTypeInfo = Depends(get_key_type)) -> List[
|
||||||
merchant = await get_merchant_for_user(wallet.wallet.user)
|
merchant = await get_merchant_for_user(wallet.wallet.user)
|
||||||
assert merchant, "Merchant cannot be found"
|
assert merchant, "Merchant cannot be found"
|
||||||
return await get_zones(merchant.id)
|
return await get_zones(merchant.id)
|
||||||
|
except AssertionError as ex:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
|
detail=str(ex),
|
||||||
|
)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logger.warning(ex)
|
logger.warning(ex)
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
@ -171,6 +181,11 @@ async def api_create_zone(
|
||||||
assert merchant, "Merchant cannot be found"
|
assert merchant, "Merchant cannot be found"
|
||||||
zone = await create_zone(merchant.id, data)
|
zone = await create_zone(merchant.id, data)
|
||||||
return zone
|
return zone
|
||||||
|
except AssertionError as ex:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
|
detail=str(ex),
|
||||||
|
)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logger.warning(ex)
|
logger.warning(ex)
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
@ -197,6 +212,11 @@ async def api_update_zone(
|
||||||
zone = await update_zone(merchant.id, data)
|
zone = await update_zone(merchant.id, data)
|
||||||
assert zone, "Cannot find updated zone"
|
assert zone, "Cannot find updated zone"
|
||||||
return zone
|
return zone
|
||||||
|
except AssertionError as ex:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
|
detail=str(ex),
|
||||||
|
)
|
||||||
except HTTPException as ex:
|
except HTTPException as ex:
|
||||||
raise ex
|
raise ex
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
|
|
@ -221,7 +241,11 @@ async def api_delete_zone(zone_id, wallet: WalletTypeInfo = Depends(require_admi
|
||||||
)
|
)
|
||||||
|
|
||||||
await delete_zone(merchant.id, zone_id)
|
await delete_zone(merchant.id, zone_id)
|
||||||
|
except AssertionError as ex:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
|
detail=str(ex),
|
||||||
|
)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logger.warning(ex)
|
logger.warning(ex)
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
@ -251,7 +275,8 @@ async def api_create_stall(
|
||||||
await update_stall(merchant.id, stall)
|
await update_stall(merchant.id, stall)
|
||||||
|
|
||||||
return stall
|
return stall
|
||||||
except ValueError as ex:
|
|
||||||
|
except (ValueError, AssertionError) as ex:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=HTTPStatus.BAD_REQUEST,
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
detail=str(ex),
|
detail=str(ex),
|
||||||
|
|
@ -286,7 +311,7 @@ async def api_update_stall(
|
||||||
return stall
|
return stall
|
||||||
except HTTPException as ex:
|
except HTTPException as ex:
|
||||||
raise ex
|
raise ex
|
||||||
except ValueError as ex:
|
except (ValueError, AssertionError) as ex:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=HTTPStatus.BAD_REQUEST,
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
detail=str(ex),
|
detail=str(ex),
|
||||||
|
|
@ -311,6 +336,11 @@ async def api_get_stall(stall_id: str, wallet: WalletTypeInfo = Depends(get_key_
|
||||||
detail="Stall does not exist.",
|
detail="Stall does not exist.",
|
||||||
)
|
)
|
||||||
return stall
|
return stall
|
||||||
|
except AssertionError as ex:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
|
detail=str(ex),
|
||||||
|
)
|
||||||
except HTTPException as ex:
|
except HTTPException as ex:
|
||||||
raise ex
|
raise ex
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
|
|
@ -328,6 +358,11 @@ async def api_get_stalls(wallet: WalletTypeInfo = Depends(get_key_type)):
|
||||||
assert merchant, "Merchant cannot be found"
|
assert merchant, "Merchant cannot be found"
|
||||||
stalls = await get_stalls(merchant.id)
|
stalls = await get_stalls(merchant.id)
|
||||||
return stalls
|
return stalls
|
||||||
|
except AssertionError as ex:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
|
detail=str(ex),
|
||||||
|
)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logger.warning(ex)
|
logger.warning(ex)
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
@ -346,6 +381,11 @@ async def api_get_stall_products(
|
||||||
assert merchant, "Merchant cannot be found"
|
assert merchant, "Merchant cannot be found"
|
||||||
products = await get_products(merchant.id, stall_id)
|
products = await get_products(merchant.id, stall_id)
|
||||||
return products
|
return products
|
||||||
|
except AssertionError as ex:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
|
detail=str(ex),
|
||||||
|
)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logger.warning(ex)
|
logger.warning(ex)
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
@ -364,6 +404,11 @@ async def api_get_stall_orders(
|
||||||
assert merchant, "Merchant cannot be found"
|
assert merchant, "Merchant cannot be found"
|
||||||
orders = await get_orders_for_stall(merchant.id, stall_id)
|
orders = await get_orders_for_stall(merchant.id, stall_id)
|
||||||
return orders
|
return orders
|
||||||
|
except AssertionError as ex:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
|
detail=str(ex),
|
||||||
|
)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logger.warning(ex)
|
logger.warning(ex)
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
@ -393,6 +438,11 @@ async def api_delete_stall(
|
||||||
stall.config.event_id = event.id
|
stall.config.event_id = event.id
|
||||||
await update_stall(merchant.id, stall)
|
await update_stall(merchant.id, stall)
|
||||||
|
|
||||||
|
except AssertionError as ex:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
|
detail=str(ex),
|
||||||
|
)
|
||||||
except HTTPException as ex:
|
except HTTPException as ex:
|
||||||
raise ex
|
raise ex
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
|
|
@ -428,7 +478,7 @@ async def api_create_product(
|
||||||
await update_product(merchant.id, product)
|
await update_product(merchant.id, product)
|
||||||
|
|
||||||
return product
|
return product
|
||||||
except ValueError as ex:
|
except (ValueError, AssertionError) as ex:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=HTTPStatus.BAD_REQUEST,
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
detail=str(ex),
|
detail=str(ex),
|
||||||
|
|
@ -465,7 +515,7 @@ async def api_update_product(
|
||||||
await update_product(merchant.id, product)
|
await update_product(merchant.id, product)
|
||||||
|
|
||||||
return product
|
return product
|
||||||
except ValueError as ex:
|
except (ValueError, AssertionError) as ex:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=HTTPStatus.BAD_REQUEST,
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
detail=str(ex),
|
detail=str(ex),
|
||||||
|
|
@ -489,6 +539,11 @@ async def api_get_product(
|
||||||
|
|
||||||
products = await get_product(merchant.id, product_id)
|
products = await get_product(merchant.id, product_id)
|
||||||
return products
|
return products
|
||||||
|
except AssertionError as ex:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
|
detail=str(ex),
|
||||||
|
)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logger.warning(ex)
|
logger.warning(ex)
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
@ -516,6 +571,11 @@ async def api_delete_product(
|
||||||
await delete_product(merchant.id, product_id)
|
await delete_product(merchant.id, product_id)
|
||||||
await sign_and_send_to_nostr(merchant, product, True)
|
await sign_and_send_to_nostr(merchant, product, True)
|
||||||
|
|
||||||
|
except AssertionError as ex:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
|
detail=str(ex),
|
||||||
|
)
|
||||||
except HTTPException as ex:
|
except HTTPException as ex:
|
||||||
raise ex
|
raise ex
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
|
|
@ -544,6 +604,11 @@ async def api_get_order(order_id: str, wallet: WalletTypeInfo = Depends(get_key_
|
||||||
detail="Order does not exist.",
|
detail="Order does not exist.",
|
||||||
)
|
)
|
||||||
return order
|
return order
|
||||||
|
except AssertionError as ex:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
|
detail=str(ex),
|
||||||
|
)
|
||||||
except HTTPException as ex:
|
except HTTPException as ex:
|
||||||
raise ex
|
raise ex
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
|
|
@ -562,6 +627,11 @@ async def api_get_orders(wallet: WalletTypeInfo = Depends(get_key_type)):
|
||||||
|
|
||||||
orders = await get_orders(merchant.id)
|
orders = await get_orders(merchant.id)
|
||||||
return orders
|
return orders
|
||||||
|
except AssertionError as ex:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
|
detail=str(ex),
|
||||||
|
)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logger.warning(ex)
|
logger.warning(ex)
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
@ -594,6 +664,11 @@ async def api_update_order_status(
|
||||||
|
|
||||||
return order
|
return order
|
||||||
|
|
||||||
|
except AssertionError as ex:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
|
detail=str(ex),
|
||||||
|
)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logger.warning(ex)
|
logger.warning(ex)
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
@ -615,6 +690,11 @@ async def api_get_messages(
|
||||||
|
|
||||||
messages = await get_direct_messages(merchant.id, public_key)
|
messages = await get_direct_messages(merchant.id, public_key)
|
||||||
return messages
|
return messages
|
||||||
|
except AssertionError as ex:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
|
detail=str(ex),
|
||||||
|
)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logger.warning(ex)
|
logger.warning(ex)
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
@ -639,6 +719,11 @@ async def api_create_message(
|
||||||
await publish_nostr_event(dm_event)
|
await publish_nostr_event(dm_event)
|
||||||
|
|
||||||
return dm
|
return dm
|
||||||
|
except AssertionError as ex:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
|
detail=str(ex),
|
||||||
|
)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logger.warning(ex)
|
logger.warning(ex)
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue