Re-authorize when token is invalid

This commit is contained in:
Râu Cao
2022-12-23 15:14:24 +07:00
parent e62bf67262
commit e1aaa2c434
2 changed files with 20 additions and 6 deletions

View File

@@ -28,8 +28,13 @@ class Lndhub
"Accept" => "application/json",
"Authorization" => "Bearer #{auth_token}"
})
data = JSON.parse(res.body)
JSON.parse(res.body)
if data.is_a?(Hash) && data["error"] && data["message"] == "bad auth"
raise "BAD_AUTH"
else
data
end
end
def create(payload)