Skip to content

Commit

Permalink
Handles exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
carllerche committed Feb 23, 2011
1 parent 8788440 commit a41a7ff
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
5 changes: 3 additions & 2 deletions lib/kirk/client/exchange.rb
Expand Up @@ -70,11 +70,12 @@ def prepare!(request)
# end # end


def onException(ex) def onException(ex)
p [ :onException, ex.message ]
puts ex.backtrace
if handler.respond_to?(:on_exception) if handler.respond_to?(:on_exception)
handler.on_exception(ex) handler.on_exception(ex)
end end

response.exception = true
group.respond(response)
end end


# def onExpire # def onExpire
Expand Down
20 changes: 15 additions & 5 deletions lib/kirk/client/response.rb
@@ -1,16 +1,26 @@
class Kirk::Client class Kirk::Client
class Response class Response
attr_accessor :version, :status, :body, :headers attr_accessor :version, :status, :body, :headers, :exception


def initialize(buffer_body) def initialize(buffer_body)
@status, @version, @headers = nil, nil, {} @status = nil
@buffer_body = buffer_body @version = nil

@headers = {}
@body = buffer_body ? "" : nil @buffer_body = buffer_body
@body = buffer_body ? "" : nil
@exception = nil
end end


def buffer_body? def buffer_body?
@buffer_body @buffer_body
end end

def success?
@status && @status < 400 && !@exception
end

def exception?
@exception
end
end end
end end
14 changes: 14 additions & 0 deletions spec/kirk/client_spec.rb
Expand Up @@ -217,6 +217,20 @@ def on_response_head(resp)
group.should have(1).responses group.should have(1).responses
@completed.should be_true @completed.should be_true
end 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 end


it "allows to set thread_pool" do it "allows to set thread_pool" do
Expand Down

0 comments on commit a41a7ff

Please sign in to comment.