From 55c720ba9f60792cf0994e95a7c8a8ca4260b084 Mon Sep 17 00:00:00 2001 From: Kevin Chan Date: Mon, 6 May 2013 10:03:36 -0700 Subject: [PATCH] Fixes #39 joyent server resize command requires expected response code --- lib/fog/joyent/compute.rb | 26 ++++++++++--------- .../joyent/requests/compute/resize_machine.rb | 3 ++- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/fog/joyent/compute.rb b/lib/fog/joyent/compute.rb index 678344692..09814f9d1 100644 --- a/lib/fog/joyent/compute.rb +++ b/lib/fog/joyent/compute.rb @@ -147,7 +147,7 @@ module Fog "X-Api-Version" => @joyent_version, "Content-Type" => "application/json", "Accept" => "application/json" - }.merge(request[:headers] || {}).merge(@header_method.call) + }.merge(request[:headers] || {}).merge(@header_method.call) if request[:body] request[:body] = Fog::JSON.encode(request[:body]) @@ -162,6 +162,8 @@ module Fog raise_if_error!(request, response) response + rescue Excon::Errors::Error => e + raise_if_error(e.request, e.response) end private @@ -213,27 +215,27 @@ module Fog def raise_if_error!(request, response) case response.status when 401 then - raise Errors::Unauthorized.new('Invalid credentials were used', request, response) + raise Joyent::Errors::Unauthorized.new('Invalid credentials were used', request, response) when 403 then - raise Errors::Forbidden.new('No permissions to the specified resource', request, response) + raise Joyent::Errors::Forbidden.new('No permissions to the specified resource', request, response) when 404 then - raise Errors::NotFound.new('Requested resource was not found', request, response) + raise Joyent::Errors::NotFound.new('Requested resource was not found', request, response) when 405 then - raise Errors::MethodNotAllowed.new('Method not supported for the given resource', request, response) + raise Joyent::Errors::MethodNotAllowed.new('Method not supported for the given resource', request, response) when 406 then - raise Errors::NotAcceptable.new('Try sending a different Accept header', request, response) + raise Joyent::Errors::NotAcceptable.new('Try sending a different Accept header', request, response) when 409 then - raise Errors::Conflict.new('Most likely invalid or missing parameters', request, response) + raise Joyent::Errors::Conflict.new('Most likely invalid or missing parameters', request, response) when 414 then - raise Errors::RequestEntityTooLarge.new('You sent too much data', request, response) + raise Joyent::Errors::RequestEntityTooLarge.new('You sent too much data', request, response) when 415 then - raise Errors::UnsupportedMediaType.new('You encoded your request in a format we don\'t understand', request, response) + raise Joyent::Errors::UnsupportedMediaType.new('You encoded your request in a format we don\'t understand', request, response) when 420 then - raise Errors::PolicyNotForfilled.new('You are sending too many requests', request, response) + raise Joyent::Errors::PolicyNotForfilled.new('You are sending too many requests', request, response) when 449 then - raise Errors::RetryWith.new('Invalid API Version requested; try with a different API Version', request, response) + raise Joyent::Errors::RetryWith.new('Invalid API Version requested; try with a different API Version', request, response) when 503 then - raise Errors::ServiceUnavailable.new('Either there\'s no capacity in this datacenter, or we\'re in a maintenance window', request, response) + raise Joyent::Errors::ServiceUnavailable.new('Either there\'s no capacity in this datacenter, or we\'re in a maintenance window', request, response) end end diff --git a/lib/fog/joyent/requests/compute/resize_machine.rb b/lib/fog/joyent/requests/compute/resize_machine.rb index 0c2a63933..943c392bb 100644 --- a/lib/fog/joyent/requests/compute/resize_machine.rb +++ b/lib/fog/joyent/requests/compute/resize_machine.rb @@ -6,7 +6,8 @@ module Fog request( :method => "POST", :path => "/my/machines/#{id}", - :query => {"action" => "resize", "package" => package} + :query => {"action" => "resize", "package" => package}, + :expects => [202] ) end end