fixing bugs in btcpay server down detection

This commit is contained in:
forest 2022-02-22 14:17:40 -06:00
parent 32cb14f979
commit 6c57e45cdd
4 changed files with 14 additions and 12 deletions

View File

@ -143,7 +143,7 @@ else:
app.config['HTTP_CLIENT'] = MyHTTPClient(timeout_seconds=int(app.config['INTERNAL_HTTP_TIMEOUT_SECONDS'])) app.config['HTTP_CLIENT'] = MyHTTPClient(timeout_seconds=int(app.config['INTERNAL_HTTP_TIMEOUT_SECONDS']))
if app.config['BTCPAY_URL'] != "": if app.config['BTCPAY_URL'] != "":
try_reconnnect_btcpay() try_reconnnect_btcpay(app)
# only start the scheduler and attempt to migrate the database if we are running the app. # only start the scheduler and attempt to migrate the database if we are running the app.
# otherwise we are running a CLI command. # otherwise we are running a CLI command.

View File

@ -1,4 +1,5 @@
import stripe import stripe
import requests
import json import json
import time import time
import decimal import decimal
@ -58,7 +59,7 @@ def btcpay_payment():
flash("BTCPay is not enabled on this server") flash("BTCPay is not enabled on this server")
return redirect(url_for("console.account_balance")) return redirect(url_for("console.account_balance"))
elif 'BTCPAY_CLIENT' not in current_app.config: elif 'BTCPAY_CLIENT' not in current_app.config:
if not try_reconnnect_btcpay(): if not try_reconnnect_btcpay(current_app):
flash("can't contact the BTCPay server right now") flash("can't contact the BTCPay server right now")
return redirect(url_for("console.account_balance")) return redirect(url_for("console.account_balance"))
@ -100,7 +101,7 @@ def btcpay_payment():
def poll_btcpay_session(invoice_id): def poll_btcpay_session(invoice_id):
if 'BTCPAY_CLIENT' not in current_app.config: if 'BTCPAY_CLIENT' not in current_app.config:
if not try_reconnnect_btcpay(): if not try_reconnnect_btcpay(current_app):
return [503, "can't contact btcpay server"] return [503, "can't contact btcpay server"]
invoice = None invoice = None
@ -139,17 +140,17 @@ def poll_btcpay_session(invoice_id):
return [200, "ok"] return [200, "ok"]
def try_reconnnect_btcpay(): def try_reconnnect_btcpay(app):
try: try:
response = requests.get(current_app.config['BTCPAY_URL']) response = requests.get(app.config['BTCPAY_URL'])
if response.status_code == 200: if response.status_code == 200:
current_app.config['BTCPAY_CLIENT'] = btcpay.Client(api_uri=current_app.config['BTCPAY_URL'], pem=current_app.config['BTCPAY_PRIVATE_KEY']) app.config['BTCPAY_CLIENT'] = btcpay.Client(api_uri=app.config['BTCPAY_URL'], pem=app.config['BTCPAY_PRIVATE_KEY'])
return True return True
else: else:
current_app.logger.warn(f"Can't reach BTCPAY_URL {current_app.config['BTCPAY_URL']}: Response status code: {response.status_code}. Capsul will work fine except cryptocurrency payments will not work.") app.logger.warn(f"Can't reach BTCPAY_URL {app.config['BTCPAY_URL']}: Response status code: {response.status_code}. Capsul will work fine except cryptocurrency payments will not work.")
return False return False
except: except:
current_app.logger.warn("unable to create btcpay client. Capsul will work fine except cryptocurrency payments will not work. The error was: " + my_exec_info_message(sys.exc_info())) app.logger.warn("unable to create btcpay client. Capsul will work fine except cryptocurrency payments will not work. The error was: " + my_exec_info_message(sys.exc_info()))
return False return False

View File

@ -53,9 +53,6 @@ a:hover, a:active, a:visited {
.error { .error {
color: rgb(173, 74, 8); color: rgb(173, 74, 8);
font-weight: bold; font-weight: bold;
border: 1px dashed rgb(173, 74, 8);
border-radius: 0.5em;
padding: 1em;
} }
.disabled { .disabled {

View File

@ -52,7 +52,11 @@
{% else %} {% else %}
<li> <li>
<span class="disabled">Add funds with Bitcoin/Litecoin/Monero (btcpay)</span> <span class="disabled">Add funds with Bitcoin/Litecoin/Monero (btcpay)</span>
<span class="error"> ERROR: the BTCPay server cannot be reached</span> <ul>
<li>
<span class="error"> ERROR: the BTCPay server cannot be reached</span>
</li>
</ul>
</li> </li>
{% endif %} {% endif %}