Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Handles exceptions

  • Loading branch information...
commit a41a7ff35231d6c2a90636e280157c2b8df20024 1 parent 8788440
Carl Lerche carllerche authored
5 lib/kirk/client/exchange.rb
View
@@ -70,11 +70,12 @@ def prepare!(request)
# end
def onException(ex)
- p [ :onException, ex.message ]
- puts ex.backtrace
if handler.respond_to?(:on_exception)
handler.on_exception(ex)
end
+
+ response.exception = true
+ group.respond(response)
end
# def onExpire
20 lib/kirk/client/response.rb
View
@@ -1,16 +1,26 @@
class Kirk::Client
class Response
- attr_accessor :version, :status, :body, :headers
+ attr_accessor :version, :status, :body, :headers, :exception
def initialize(buffer_body)
- @status, @version, @headers = nil, nil, {}
- @buffer_body = buffer_body
-
- @body = buffer_body ? "" : nil
+ @status = nil
+ @version = nil
+ @headers = {}
+ @buffer_body = buffer_body
+ @body = buffer_body ? "" : nil
+ @exception = nil
end
def buffer_body?
@buffer_body
end
+
+ def success?
+ @status && @status < 400 && !@exception
+ end
+
+ def exception?
+ @exception
+ end
end
end
14 spec/kirk/client_spec.rb
View
@@ -217,6 +217,20 @@ def on_response_head(resp)
group.should have(1).responses
@completed.should be_true
end
+
+ it "handles exceptions in the callbacks" do
+ start_default_app
+
+ handler = Class.new do
+ def on_request_complete(*)
+ raise "fail"
+ end
+ end
+
+ resp = Kirk::Client.get 'http://localhost:9090/', handler.new
+ resp.success?.should be_false
+ resp.exception?.should be_true
+ end
end
it "allows to set thread_pool" do
Please sign in to comment.
Something went wrong with that request. Please try again.