Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Handles exceptions

  • Loading branch information...
commit a41a7ff35231d6c2a90636e280157c2b8df20024 1 parent 8788440
Carl Lerche carllerche authored
5 lib/kirk/client/exchange.rb
@@ -70,11 +70,12 @@ def prepare!(request)
70 70 # end
71 71
72 72 def onException(ex)
73   - p [ :onException, ex.message ]
74   - puts ex.backtrace
75 73 if handler.respond_to?(:on_exception)
76 74 handler.on_exception(ex)
77 75 end
  76 +
  77 + response.exception = true
  78 + group.respond(response)
78 79 end
79 80
80 81 # def onExpire
20 lib/kirk/client/response.rb
... ... @@ -1,16 +1,26 @@
1 1 class Kirk::Client
2 2 class Response
3   - attr_accessor :version, :status, :body, :headers
  3 + attr_accessor :version, :status, :body, :headers, :exception
4 4
5 5 def initialize(buffer_body)
6   - @status, @version, @headers = nil, nil, {}
7   - @buffer_body = buffer_body
8   -
9   - @body = buffer_body ? "" : nil
  6 + @status = nil
  7 + @version = nil
  8 + @headers = {}
  9 + @buffer_body = buffer_body
  10 + @body = buffer_body ? "" : nil
  11 + @exception = nil
10 12 end
11 13
12 14 def buffer_body?
13 15 @buffer_body
14 16 end
  17 +
  18 + def success?
  19 + @status && @status < 400 && !@exception
  20 + end
  21 +
  22 + def exception?
  23 + @exception
  24 + end
15 25 end
16 26 end
14 spec/kirk/client_spec.rb
@@ -217,6 +217,20 @@ def on_response_head(resp)
217 217 group.should have(1).responses
218 218 @completed.should be_true
219 219 end
  220 +
  221 + it "handles exceptions in the callbacks" do
  222 + start_default_app
  223 +
  224 + handler = Class.new do
  225 + def on_request_complete(*)
  226 + raise "fail"
  227 + end
  228 + end
  229 +
  230 + resp = Kirk::Client.get 'http://localhost:9090/', handler.new
  231 + resp.success?.should be_false
  232 + resp.exception?.should be_true
  233 + end
220 234 end
221 235
222 236 it "allows to set thread_pool" do

0 comments on commit a41a7ff

Please sign in to comment.
Something went wrong with that request. Please try again.