From 17c18679e235ccbe3df5c1c85f25262556ed468e Mon Sep 17 00:00:00 2001 From: Brandon High Date: Tue, 3 Dec 2019 17:00:41 -0800 Subject: [PATCH] Update pooler provider to throw an exception if the API returns non-OK Prior to this commit the API could fail and return `ok: false` but floaty wouldn't recognize that as a failure. This commit updates the pooler code to check for `ok` and raise and error with the body of what the api returns if it's non-truthy. --- lib/vmfloaty/pooler.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/vmfloaty/pooler.rb b/lib/vmfloaty/pooler.rb index a735c3b..b8a492e 100644 --- a/lib/vmfloaty/pooler.rb +++ b/lib/vmfloaty/pooler.rb @@ -72,7 +72,14 @@ def self.modify(verbose, url, hostname, token, modify_hash) end res_body = JSON.parse(response.body) - res_body + + if res_body['ok'] + res_body + elsif response.status == 401 + raise AuthError, "HTTP #{response.status}: The token provided could not authenticate to the pooler.\n#{res_body}" + else + raise ModifyError, "HTTP #{response.status}: Failed to modify VMs from the pooler vm/#{hostname}. #{res_body}" + end end def self.disk(verbose, url, hostname, token, disk)