-
-
Notifications
You must be signed in to change notification settings - Fork 326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: raise failed request to not run mark_webhook_sent
#2289
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #2289 +/- ##
==========================================
- Coverage 58.63% 58.55% -0.09%
==========================================
Files 61 61
Lines 9192 9205 +13
==========================================
Hits 5390 5390
- Misses 3802 3815 +13 ☔ View full report in Codecov by Sentry. |
mark_webhook_sent
In try:
r = await client.post(payment.webhook, json=data, timeout=40)
await mark_webhook_sent(payment, r.status_code)
except (httpx.ConnectError, httpx.RequestError):
await mark_webhook_sent(payment, -1) There are 3 places where this pattern ☝️ is repeated. |
5742f68
to
80d41f6
Compare
i was actually misinterpreting the code, we don't want to raise an HTTPStatusException here, because we actually want to set the status code to 404 or 500 if it fails to see if the response was not ok. we just want to set status -1 when we cannot even send the request. i also saw that mark_webhook_sent is actually saved twice, for |
@@ -51,7 +51,7 @@ async def killswitch_task(): | |||
"Switching to VoidWallet. Killswitch triggered." | |||
) | |||
await switch_to_voidwallet() | |||
except (httpx.ConnectError, httpx.RequestError): | |||
except (httpx.RequestError, httpx.HTTPStatusError): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is httpx.ConnectError
not ever thrown?
Can we just catch Error
and log the actual error?
Is there a case when the error should bubble up (and stop the loop)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ConnectError is capture by RequestError look at the exception tree here. it was redundant. https://www.python-httpx.org/exceptions/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
statuserror is triggerbe by raise_for_status()
and is raised if the response has a bad status code
pass | ||
r.raise_for_status() | ||
await mark_webhook_sent(payment.payment_hash, r.status_code) | ||
except httpx.HTTPStatusError as exc: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which is the difference between the two catch clauses (httpx.HTTPStatusError
vs httpx.RequestError
), why are they handled differently?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
request error is the request never reached the server, httperror is it hits the server but returns a bad statuscode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are they handled differently though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because we want to save the bad statuscode inside the payment details, it was like that before. so we know we did send it, but the receiver couldnt handle it.
is not raised even failed webhook would be marked is sent
51981da
to
cf9bd03
Compare
error is not raised, even if failed webhook would be marked as sent every time