Skip to content
Snippets Groups Projects
Commit 0634b52a authored by Pelle Koster's avatar Pelle Koster
Browse files

better exception handling

parent 7300318d
Branches
Tags
No related merge requests found
......@@ -16,7 +16,7 @@ VALID_EVENTS = [
PAYMENT_INTENT_CANCELED,
]
RAISE_EXCEPTIONS = True
RAISE_EXCEPTIONS = False
UNPROCESSED_PAYMENT_EMAIL_TEMPLATE = """\
A payment was made in Stripe that could not be linked to a Visitor. Please process this
......@@ -43,11 +43,11 @@ class Command(BaseCommand):
else:
msg = self.style.SUCCESS(f"{prefix} success!")
except Exception:
msg = self.style.ERROR(f"{prefix} error!")
self.stdout.write(self.style.ERROR(f"{prefix} error!"))
if RAISE_EXCEPTIONS:
raise
traceback.print_exc()
finally:
else:
event.handled = True
event.save()
self.stdout.write(msg)
......@@ -77,7 +77,11 @@ class Command(BaseCommand):
if order is None:
return self._notify_unprocessed_payment(payment_intent)
api = VisitorAPI()
visitor = api.get_visitor(order.visitor_id)
visitor = api.get_visitor_or_none(order.visitor_id)
if visitor is None:
self.stdout.write(self.style.ERROR("Visitor not found!"))
return self._notify_unprocessed_payment(payment_intent)
for item in order.items.all():
if item.kind == ItemKind.REGISTRATION_TYPE:
visitor.paid = True
......@@ -94,7 +98,12 @@ class Command(BaseCommand):
if order is None:
return False
api = VisitorAPI()
visitor = api.get_visitor(order.visitor_id)
visitor = api.get_visitor_or_none(order.visitor_id)
if visitor is None:
self.stdout.write(
self.style.ERROR("Visitor not found! Not processing cancellation")
)
return
visitor.canceled = True
api.update_visitor(visitor)
order.canceled = True
......
......@@ -76,6 +76,14 @@ class VisitorAPI:
raise Http404()
return Visitor.from_api(result)
def get_visitor_or_none(
self, visitor_id: str, allow_deleted=False
) -> Optional[Visitor]:
try:
return self.get_visitor(visitor_id, allow_deleted)
except Http404:
return None
def update_visitor(
self, visitor: Union[str, Visitor], payload: Optional[dict] = None
):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment