diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-10-22 16:21:03 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2010-10-22 16:21:03 -0700 |
commit | 180485d49ea858f83ef2a28a9e07224aa514edc7 (patch) | |
tree | b4c649d2118c0010bf3876a49dadfe3e4cbc3f86 /lib/rainbows/error.rb | |
parent | 41145ed4d335718ac43aec9313b7571a12fe96ee (diff) | |
download | rainbows-180485d49ea858f83ef2a28a9e07224aa514edc7.tar.gz |
This simplifies and disambiguates most constant resolution issues as well as lowering our identation level. Hopefully this makes code easier to understand.
Diffstat (limited to 'lib/rainbows/error.rb')
-rw-r--r-- | lib/rainbows/error.rb | 72 |
1 files changed, 34 insertions, 38 deletions
diff --git a/lib/rainbows/error.rb b/lib/rainbows/error.rb index 7c91050..bdbfdc5 100644 --- a/lib/rainbows/error.rb +++ b/lib/rainbows/error.rb @@ -1,48 +1,44 @@ # -*- encoding: binary -*- # :enddoc: -module Rainbows +module Rainbows::Error - class Error - class << self + G = Rainbows::G - # if we get any error, try to write something back to the client - # assuming we haven't closed the socket, but don't get hung up - # if the socket is already closed or broken. We'll always ensure - # the socket is closed at the end of this function - def write(io, e) - msg = Error.response(e) and io.write_nonblock(msg) - rescue - end - - def app(e) - G.server.logger.error "app error: #{e.inspect}" - G.server.logger.error e.backtrace.join("\n") - rescue - end + # if we get any error, try to write something back to the client + # assuming we haven't closed the socket, but don't get hung up + # if the socket is already closed or broken. We'll always ensure + # the socket is closed at the end of this function + def self.write(io, e) + msg = response(e) and io.write_nonblock(msg) + rescue + end - def listen_loop(e) - G.alive or return - G.server.logger.error "listen loop error: #{e.inspect}." - G.server.logger.error e.backtrace.join("\n") - rescue - end + def self.app(e) + G.server.logger.error "app error: #{e.inspect}" + G.server.logger.error e.backtrace.join("\n") + rescue + end - def response(e) - case e - when EOFError, Errno::ECONNRESET, Errno::EPIPE, Errno::EINVAL, - Errno::EBADF, Errno::ENOTCONN - # swallow error if client shuts down one end or disconnects - when Rainbows::Response416 - Const::ERROR_416_RESPONSE - when Unicorn::HttpParserError - Const::ERROR_400_RESPONSE # try to tell the client they're bad - when IOError # HttpParserError is an IOError - else - app(e) - Const::ERROR_500_RESPONSE - end - end + def self.listen_loop(e) + G.alive or return + G.server.logger.error "listen loop error: #{e.inspect}." + G.server.logger.error e.backtrace.join("\n") + rescue + end + def self.response(e) + case e + when EOFError, Errno::ECONNRESET, Errno::EPIPE, Errno::EINVAL, + Errno::EBADF, Errno::ENOTCONN + # swallow error if client shuts down one end or disconnects + when Rainbows::Response416 + Rainbows::Const::ERROR_416_RESPONSE + when Unicorn::HttpParserError + Rainbows::Const::ERROR_400_RESPONSE # try to tell the client they're bad + when IOError # HttpParserError is an IOError + else + app(e) + Rainbows::Const::ERROR_500_RESPONSE end end end |