bump required Unicorn dependency for Kgio
[rainbows.git] / lib / rainbows / error.rb
blob039af9daa8abe37ede2f8606619b1020a509e0c3
1 # -*- encoding: binary -*-
2 # :enddoc:
3 module Rainbows::Error
5   # if we get any error, try to write something back to the client
6   # assuming we haven't closed the socket, but don't get hung up
7   # if the socket is already closed or broken.  We'll always ensure
8   # the socket is closed at the end of this function
9   def self.write(io, e)
10     msg = response(e) and Kgio.trywrite(io, msg)
11     rescue
12   end
14   def self.app(e)
15     Rainbows.server.logger.error "app error: #{e.inspect}"
16     Rainbows.server.logger.error e.backtrace.join("\n")
17     rescue
18   end
20   def self.listen_loop(e)
21     Rainbows.alive or return
22     Rainbows.server.logger.error "listen loop error: #{e.inspect}."
23     Rainbows.server.logger.error e.backtrace.join("\n")
24     rescue
25   end
27   def self.response(e)
28     case e
29     when EOFError, Errno::ECONNRESET, Errno::EPIPE, Errno::EINVAL,
30          Errno::EBADF, Errno::ENOTCONN
31       # swallow error if client shuts down one end or disconnects
32     when Unicorn::HttpParserError
33       Rainbows::Const::ERROR_400_RESPONSE # try to tell the client they're bad
34     when IOError # HttpParserError is an IOError
35     else
36       app(e)
37       Rainbows::Const::ERROR_500_RESPONSE
38     end
39   end
40 end