diff --git a/app/controllers/services/lightning_controller.rb b/app/controllers/services/lightning_controller.rb index 9e39feb..51b7dbd 100644 --- a/app/controllers/services/lightning_controller.rb +++ b/app/controllers/services/lightning_controller.rb @@ -49,9 +49,9 @@ class Services::LightningController < ApplicationController lndhub = Lndhub.new data = lndhub.balance @ln_auth_token @balance = data["BTC"]["AvailableBalance"] rescue nil - rescue + rescue AuthError authenticate_with_lndhub(force_reauth: true) - return nil if @fetch_balance_retried + raise if @fetch_balance_retried @fetch_balance_retried = true fetch_balance end @@ -61,9 +61,9 @@ class Services::LightningController < ApplicationController txs = lndhub.gettxs @ln_auth_token invoices = lndhub.getuserinvoices(@ln_auth_token).select{|i| i["ispaid"]} process_transactions(txs + invoices) - rescue + rescue AuthError authenticate_with_lndhub(force_reauth: true) - return [] if @fetch_transactions_retried + raise if @fetch_transactions_retried @fetch_transactions_retried = true fetch_transactions end diff --git a/app/errors/auth_error.rb b/app/errors/auth_error.rb new file mode 100644 index 0000000..4d55106 --- /dev/null +++ b/app/errors/auth_error.rb @@ -0,0 +1 @@ +class AuthError < StandardError; end diff --git a/app/services/lndhub.rb b/app/services/lndhub.rb index 4c8ad66..44b7880 100644 --- a/app/services/lndhub.rb +++ b/app/services/lndhub.rb @@ -26,7 +26,7 @@ class Lndhub data = JSON.parse(res.body) if data.is_a?(Hash) && data["error"] && data["message"] == "bad auth" - raise "BAD_AUTH" + raise AuthError else data end