mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
get expected status code or raise errors
This commit is contained in:
parent
dde87c424b
commit
a6ec973792
16 changed files with 66 additions and 1 deletions
|
@ -108,6 +108,7 @@ module Fog
|
|||
|
||||
response = @connection.request({
|
||||
:body => body,
|
||||
:expects => 200,
|
||||
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
|
||||
:host => @host,
|
||||
:method => 'POST',
|
||||
|
|
|
@ -6,6 +6,7 @@ module Fog
|
|||
# FIXME: docs
|
||||
def copy_object(source_bucket_name, source_object_name, destination_bucket_name, destination_object_name)
|
||||
request({
|
||||
:expects => 200,
|
||||
:headers => { 'x-amz-copy-source' => "/#{source_bucket_name}/#{source_object_name}" },
|
||||
:host => "#{destination_bucket_name}.#{@host}",
|
||||
:method => 'PUT',
|
||||
|
|
|
@ -11,6 +11,7 @@ module Fog
|
|||
# FIXME: docs
|
||||
def delete_bucket(bucket_name)
|
||||
request({
|
||||
:expects => 204,
|
||||
:headers => {},
|
||||
:host => "#{bucket_name}.#{@host}",
|
||||
:method => 'DELETE'
|
||||
|
|
|
@ -6,6 +6,7 @@ module Fog
|
|||
# FIXME: docs
|
||||
def delete_object(bucket_name, object_name)
|
||||
request({
|
||||
:expects => 204,
|
||||
:headers => {},
|
||||
:host => "#{bucket_name}.#{@host}",
|
||||
:method => 'DELETE',
|
||||
|
|
|
@ -21,6 +21,7 @@ module Fog
|
|||
end
|
||||
query.chop!
|
||||
request({
|
||||
:expects => 200,
|
||||
:headers => {},
|
||||
:host => "#{bucket_name}.#{@host}",
|
||||
:method => 'GET',
|
||||
|
|
|
@ -11,6 +11,7 @@ module Fog
|
|||
# FIXME: docs
|
||||
def get_bucket_location(bucket_name)
|
||||
request({
|
||||
:expects => 200,
|
||||
:headers => {},
|
||||
:host => "#{bucket_name}.#{@host}",
|
||||
:method => 'GET',
|
||||
|
|
|
@ -6,6 +6,7 @@ module Fog
|
|||
# FIXME: docs
|
||||
def get_object(bucket_name, object_name)
|
||||
request({
|
||||
:expects => 200,
|
||||
:headers => {},
|
||||
:host => "#{bucket_name}.#{@host}",
|
||||
:method => 'GET',
|
||||
|
|
|
@ -11,6 +11,7 @@ module Fog
|
|||
# FIXME: docs
|
||||
def get_request_payment(bucket_name)
|
||||
request({
|
||||
:expects => 200,
|
||||
:headers => {},
|
||||
:host => "#{bucket_name}.#{@host}",
|
||||
:method => 'GET',
|
||||
|
|
|
@ -8,6 +8,7 @@ module Fog
|
|||
# FIXME: docs
|
||||
def get_service
|
||||
request({
|
||||
:expects => 200,
|
||||
:headers => {},
|
||||
:host => @host,
|
||||
:method => 'GET',
|
||||
|
|
|
@ -6,6 +6,7 @@ module Fog
|
|||
# FIXME: docs
|
||||
def head_object(bucket_name, object_name)
|
||||
request({
|
||||
:expects => 200,
|
||||
:headers => {},
|
||||
:host => "#{bucket_name}.#{@host}",
|
||||
:method => 'HEAD',
|
||||
|
|
|
@ -20,6 +20,7 @@ DATA
|
|||
data = nil
|
||||
end
|
||||
request({
|
||||
:expects => 200,
|
||||
:body => data,
|
||||
:headers => {},
|
||||
:host => "#{bucket_name}.#{@host}",
|
||||
|
|
|
@ -8,6 +8,7 @@ module Fog
|
|||
file = parse_file(object)
|
||||
request({
|
||||
:body => file[:body],
|
||||
:expects => 200,
|
||||
:headers => options.merge!(file[:headers]),
|
||||
:host => "#{bucket_name}.#{@host}",
|
||||
:method => 'PUT',
|
||||
|
|
|
@ -16,6 +16,7 @@ module Fog
|
|||
DATA
|
||||
request({
|
||||
:body => data,
|
||||
:expects => 200,
|
||||
:headers => {},
|
||||
:host => "#{bucket_name}.#{@host}",
|
||||
:method => 'PUT',
|
||||
|
|
|
@ -122,6 +122,7 @@ DATA
|
|||
|
||||
response = @connection.request({
|
||||
:body => params[:body],
|
||||
:expects => params[:expects],
|
||||
:headers => params[:headers],
|
||||
:host => params[:host],
|
||||
:method => params[:method],
|
||||
|
|
|
@ -135,6 +135,7 @@ module Fog
|
|||
|
||||
response = @connection.request({
|
||||
:body => body,
|
||||
:expects => 200,
|
||||
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
|
||||
:host => @host,
|
||||
:method => 'POST',
|
||||
|
|
|
@ -20,6 +20,52 @@ module Fog
|
|||
end
|
||||
end
|
||||
|
||||
# Messages for nicer exceptions, from rfc2616
|
||||
def error_message(expected, actual)
|
||||
@messages ||= {
|
||||
100 => 'Continue',
|
||||
101 => 'Switching Protocols',
|
||||
200 => 'OK',
|
||||
201 =>'Created',
|
||||
202 => 'Accepted',
|
||||
203 => 'Non-Authoritative Information',
|
||||
204 => 'No Content',
|
||||
205 => 'Reset Content',
|
||||
206 => 'Partial Content',
|
||||
300 => 'Multiple Choices',
|
||||
301 => 'Moved Permanently',
|
||||
302 => 'Found',
|
||||
303 => 'See Other',
|
||||
304 => 'Not Modified',
|
||||
305 => 'Use Proxy',
|
||||
307 => 'Temporary Redirect',
|
||||
400 => 'Bad Request',
|
||||
401 => 'Unauthorized',
|
||||
402 => 'Payment Required',
|
||||
403 => 'Forbidden',
|
||||
404 => 'Not Found',
|
||||
405 => 'Method Not Allowed',
|
||||
406 => 'Not Acceptable',
|
||||
407 => 'Proxy Authentication Required',
|
||||
408 => 'Request Timeout',
|
||||
409 => 'Conflict',
|
||||
410 => 'Gone',
|
||||
411 => 'Length Required',
|
||||
412 => 'Precondition Failed',
|
||||
413 => 'Request Entity Too Large',
|
||||
414 => 'Request-URI Too Long',
|
||||
415 => 'Unsupported Media Type',
|
||||
416 => 'Requested Range Not Satisfiable',
|
||||
417 => 'Expectation Failed',
|
||||
500 => 'Internal Server Error',
|
||||
501 => 'Not Implemented',
|
||||
502 => 'Bad Gateway',
|
||||
503 => 'Service Unavailable',
|
||||
504 => 'Gateway Timeout'
|
||||
}
|
||||
"Expected(#{expected} #{@messages[expected]}) <=> Got(#{actual} #{@messages[actual]})"
|
||||
end
|
||||
|
||||
def request(params)
|
||||
params[:path] ||= ''
|
||||
unless params[:path][0] == '/'
|
||||
|
@ -80,7 +126,11 @@ module Fog
|
|||
response.body = body
|
||||
end
|
||||
|
||||
response
|
||||
if params[:expects] && params[:expects] != response.status
|
||||
raise(error_message(params[:expects], response.status))
|
||||
else
|
||||
response
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
|
Loading…
Add table
Reference in a new issue