Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add ignorant error handling for em-http-request, fixes #2 TODO:

fix cool.io too, but not for now, and i doubt if anyone is using it...
  • Loading branch information...
commit d5ce4bf3a74648dbba8d69ba00b21d371c1af6b9 1 parent f1a52df
Lin Jen-Shin (godfat) godfat authored
1  TODO.md
View
@@ -8,6 +8,7 @@
# BUG
* inheritance should work; assign builder?
+* no error handling in cool.io
# FEATURE
17 lib/rest-core/app/em-http-request-async.rb
View
@@ -13,13 +13,8 @@ def call env
:body => payload.read,
:head => payload.headers.merge(env[REQUEST_HEADERS]))
- client.callback{
- env[TIMER].cancel if env[TIMER]
- env[ASYNC].call(env.merge(
- RESPONSE_BODY => client.response,
- RESPONSE_STATUS => client.response_header.status,
- RESPONSE_HEADERS => client.response_header)) if env[ASYNC]
- }
+ client.callback{ respond(env, client) }
+ client. errback{ respond(env, client) }
env[TIMER].on_timeout{
client.close
@@ -31,4 +26,12 @@ def call env
env
end
+
+ def respond env, client
+ env[TIMER].cancel if env[TIMER]
+ env[ASYNC].call(env.merge(
+ RESPONSE_BODY => client.response,
+ RESPONSE_STATUS => client.response_header.status,
+ RESPONSE_HEADERS => client.response_header)) if env[ASYNC]
+ end
end
11 lib/rest-core/app/em-http-request-fiber.rb
View
@@ -16,10 +16,8 @@ def call env
:body => payload.read,
:head => payload.headers.merge(env[REQUEST_HEADERS]))
- client.callback{
- env[TIMER].cancel if env[TIMER]
- f.resume(process(env, client)) if f.alive?
- }
+ client.callback{ respond(f, env, client) }
+ client. errback{ respond(f, env, client) }
if (response = Fiber.yield).kind_of?(::Exception)
client.close
@@ -29,6 +27,11 @@ def call env
end
end
+ def respond f, env, client
+ env[TIMER].cancel if env[TIMER]
+ f.resume(process(env, client)) if f.alive?
+ end
+
def process env, client
result = env.merge(RESPONSE_BODY => client.response,
RESPONSE_STATUS => client.response_header.status,
Please sign in to comment.
Something went wrong with that request. Please try again.