From c22186b461c7f73f0a083dae3d40eebab09d7139 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 15 Oct 2008 17:27:57 -0700 Subject: [PATCH] HTTPFile: use a standard set of exceptions here, too Again, easier to trap under MogileFS::Error is better --- lib/mogilefs/httpfile.rb | 12 +++++++++--- test/test_mogilefs.rb | 13 +++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/mogilefs/httpfile.rb b/lib/mogilefs/httpfile.rb index ece9834..7af2d31 100644 --- a/lib/mogilefs/httpfile.rb +++ b/lib/mogilefs/httpfile.rb @@ -18,6 +18,10 @@ require 'mogilefs/util' class MogileFS::HTTPFile < StringIO include MogileFS::Util + class EmptyResponseError < MogileFS::Error; end + class BadResponseError < MogileFS::Error; end + class UnparseableResponseError < MogileFS::Error; end + ## # The path this file will be stored to. @@ -95,17 +99,19 @@ class MogileFS::HTTPFile < StringIO if connected? then line = @socket.gets - raise 'Unable to read response line from server' if line.nil? + if line.nil? + raise EmptyResponseError, 'Unable to read response line from server' + end if line =~ %r%^HTTP/\d+\.\d+\s+(\d+)% then status = Integer $1 case status when 200..299 then # success! else - raise "HTTP response status from upload: #{status}" + raise BadResponseError, "HTTP response status from upload: #{status}" end else - raise "Response line not understood: #{line}" + raise InvalidResponseError, "Response line not understood: #{line}" end @socket.close diff --git a/test/test_mogilefs.rb b/test/test_mogilefs.rb index 6ac9d55..fafb9cf 100644 --- a/test/test_mogilefs.rb +++ b/test/test_mogilefs.rb @@ -203,6 +203,19 @@ data assert_empty TCPSocket.connections end + def test_store_content_http_fail + TCPSocket.sockets << FakeSocket.new('HTTP/1.0 500 Internal Server Error') + + @backend.create_open = { + 'devid' => '1', + 'path' => 'http://example.com/path', + } + + assert_raises MogileFS::HTTPFile::BadResponseError do + @client.store_content 'new_key', 'test', 'data' + end + end + def test_store_content_http_empty socket = FakeSocket.new 'HTTP/1.0 200 OK' -- 2.11.4.GIT