Raise custom auth error, re-raise on failed re-auth
This commit is contained in:
parent
82019f47be
commit
8b87072485
@ -49,9 +49,9 @@ class Services::LightningController < ApplicationController
|
|||||||
lndhub = Lndhub.new
|
lndhub = Lndhub.new
|
||||||
data = lndhub.balance @ln_auth_token
|
data = lndhub.balance @ln_auth_token
|
||||||
@balance = data["BTC"]["AvailableBalance"] rescue nil
|
@balance = data["BTC"]["AvailableBalance"] rescue nil
|
||||||
rescue
|
rescue AuthError
|
||||||
authenticate_with_lndhub(force_reauth: true)
|
authenticate_with_lndhub(force_reauth: true)
|
||||||
return nil if @fetch_balance_retried
|
raise if @fetch_balance_retried
|
||||||
@fetch_balance_retried = true
|
@fetch_balance_retried = true
|
||||||
fetch_balance
|
fetch_balance
|
||||||
end
|
end
|
||||||
@ -61,9 +61,9 @@ class Services::LightningController < ApplicationController
|
|||||||
txs = lndhub.gettxs @ln_auth_token
|
txs = lndhub.gettxs @ln_auth_token
|
||||||
invoices = lndhub.getuserinvoices(@ln_auth_token).select{|i| i["ispaid"]}
|
invoices = lndhub.getuserinvoices(@ln_auth_token).select{|i| i["ispaid"]}
|
||||||
process_transactions(txs + invoices)
|
process_transactions(txs + invoices)
|
||||||
rescue
|
rescue AuthError
|
||||||
authenticate_with_lndhub(force_reauth: true)
|
authenticate_with_lndhub(force_reauth: true)
|
||||||
return [] if @fetch_transactions_retried
|
raise if @fetch_transactions_retried
|
||||||
@fetch_transactions_retried = true
|
@fetch_transactions_retried = true
|
||||||
fetch_transactions
|
fetch_transactions
|
||||||
end
|
end
|
||||||
|
1
app/errors/auth_error.rb
Normal file
1
app/errors/auth_error.rb
Normal file
@ -0,0 +1 @@
|
|||||||
|
class AuthError < StandardError; end
|
@ -26,7 +26,7 @@ class Lndhub
|
|||||||
data = JSON.parse(res.body)
|
data = JSON.parse(res.body)
|
||||||
|
|
||||||
if data.is_a?(Hash) && data["error"] && data["message"] == "bad auth"
|
if data.is_a?(Hash) && data["error"] && data["message"] == "bad auth"
|
||||||
raise "BAD_AUTH"
|
raise AuthError
|
||||||
else
|
else
|
||||||
data
|
data
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user