better error handling when the btcpay server goes down
This commit is contained in:
parent
3346a45ed4
commit
5a67a58f98
@ -142,8 +142,12 @@ app.config['HTTP_CLIENT'] = MyHTTPClient(timeout_seconds=int(app.config['INTERNA
|
||||
app.config['BTCPAY_ENABLED'] = False
|
||||
if app.config['BTCPAY_URL'] != "":
|
||||
try:
|
||||
app.config['BTCPAY_CLIENT'] = btcpay.Client(api_uri=app.config['BTCPAY_URL'], pem=app.config['BTCPAY_PRIVATE_KEY'])
|
||||
app.config['BTCPAY_ENABLED'] = True
|
||||
response = requests.get(app.config['BTCPAY_URL'])
|
||||
if response.status_code == 200:
|
||||
app.config['BTCPAY_CLIENT'] = btcpay.Client(api_uri=app.config['BTCPAY_URL'], pem=app.config['BTCPAY_PRIVATE_KEY'])
|
||||
app.config['BTCPAY_ENABLED'] = True
|
||||
else:
|
||||
app.logger.warning(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.")
|
||||
except:
|
||||
app.logger.warning("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()))
|
||||
|
||||
|
@ -58,14 +58,19 @@ def btcpay_payment():
|
||||
dollars = result[1]
|
||||
|
||||
if len(errors) == 0:
|
||||
invoice = current_app.config['BTCPAY_CLIENT'].create_invoice(dict(
|
||||
price=float(dollars),
|
||||
currency="USD",
|
||||
itemDesc="Capsul Cloud Compute",
|
||||
transactionSpeed="high",
|
||||
redirectURL=f"{current_app.config['BASE_URL']}/console/account-balance",
|
||||
notificationURL=f"{current_app.config['BASE_URL']}/payment/btcpay/webhook"
|
||||
))
|
||||
try:
|
||||
invoice = current_app.config['BTCPAY_CLIENT'].create_invoice(dict(
|
||||
price=float(dollars),
|
||||
currency="USD",
|
||||
itemDesc="Capsul Cloud Compute",
|
||||
transactionSpeed="high",
|
||||
redirectURL=f"{current_app.config['BASE_URL']}/console/account-balance",
|
||||
notificationURL=f"{current_app.config['BASE_URL']}/payment/btcpay/webhook"
|
||||
))
|
||||
except:
|
||||
current_app.logger.error(f"An error occurred while attempting to reach BTCPay Server: {my_exec_info_message(sys.exc_info())}")
|
||||
flash("An error occurred while attempting to reach BTCPay Server.")
|
||||
return redirect(url_for("console.account_balance"))
|
||||
|
||||
current_app.logger.info(f"created btcpay invoice: {invoice}")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user