Skip to content

Commit 55c720b

Browse files
committed
Fixes fog#39 joyent server resize command requires expected response code
1 parent cae566a commit 55c720b

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

lib/fog/joyent/compute.rb

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def request(request = {})
147147
"X-Api-Version" => @joyent_version,
148148
"Content-Type" => "application/json",
149149
"Accept" => "application/json"
150-
}.merge(request[:headers] || {}).merge(@header_method.call)
150+
}.merge(request[:headers] || {}).merge(@header_method.call)
151151

152152
if request[:body]
153153
request[:body] = Fog::JSON.encode(request[:body])
@@ -162,6 +162,8 @@ def request(request = {})
162162
raise_if_error!(request, response)
163163

164164
response
165+
rescue Excon::Errors::Error => e
166+
raise_if_error(e.request, e.response)
165167
end
166168

167169
private
@@ -213,27 +215,27 @@ def decode_time_attrs(obj)
213215
def raise_if_error!(request, response)
214216
case response.status
215217
when 401 then
216-
raise Errors::Unauthorized.new('Invalid credentials were used', request, response)
218+
raise Joyent::Errors::Unauthorized.new('Invalid credentials were used', request, response)
217219
when 403 then
218-
raise Errors::Forbidden.new('No permissions to the specified resource', request, response)
220+
raise Joyent::Errors::Forbidden.new('No permissions to the specified resource', request, response)
219221
when 404 then
220-
raise Errors::NotFound.new('Requested resource was not found', request, response)
222+
raise Joyent::Errors::NotFound.new('Requested resource was not found', request, response)
221223
when 405 then
222-
raise Errors::MethodNotAllowed.new('Method not supported for the given resource', request, response)
224+
raise Joyent::Errors::MethodNotAllowed.new('Method not supported for the given resource', request, response)
223225
when 406 then
224-
raise Errors::NotAcceptable.new('Try sending a different Accept header', request, response)
226+
raise Joyent::Errors::NotAcceptable.new('Try sending a different Accept header', request, response)
225227
when 409 then
226-
raise Errors::Conflict.new('Most likely invalid or missing parameters', request, response)
228+
raise Joyent::Errors::Conflict.new('Most likely invalid or missing parameters', request, response)
227229
when 414 then
228-
raise Errors::RequestEntityTooLarge.new('You sent too much data', request, response)
230+
raise Joyent::Errors::RequestEntityTooLarge.new('You sent too much data', request, response)
229231
when 415 then
230-
raise Errors::UnsupportedMediaType.new('You encoded your request in a format we don\'t understand', request, response)
232+
raise Joyent::Errors::UnsupportedMediaType.new('You encoded your request in a format we don\'t understand', request, response)
231233
when 420 then
232-
raise Errors::PolicyNotForfilled.new('You are sending too many requests', request, response)
234+
raise Joyent::Errors::PolicyNotForfilled.new('You are sending too many requests', request, response)
233235
when 449 then
234-
raise Errors::RetryWith.new('Invalid API Version requested; try with a different API Version', request, response)
236+
raise Joyent::Errors::RetryWith.new('Invalid API Version requested; try with a different API Version', request, response)
235237
when 503 then
236-
raise Errors::ServiceUnavailable.new('Either there\'s no capacity in this datacenter, or we\'re in a maintenance window', request, response)
238+
raise Joyent::Errors::ServiceUnavailable.new('Either there\'s no capacity in this datacenter, or we\'re in a maintenance window', request, response)
237239
end
238240
end
239241

lib/fog/joyent/requests/compute/resize_machine.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ def resize_machine(id, package)
66
request(
77
:method => "POST",
88
:path => "/my/machines/#{id}",
9-
:query => {"action" => "resize", "package" => package}
9+
:query => {"action" => "resize", "package" => package},
10+
:expects => [202]
1011
)
1112
end
1213
end

0 commit comments

Comments
 (0)