rainbows.git  about / heads / tags
Unicorn for sleepy apps and slow clients
blob 2d8cd947255d89438f5b0d8e9d1c32aa815a70ab 883 bytes (raw)
$ git show v0.9.0:lib/rainbows/error.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
 
# -*- encoding: binary -*-
module Rainbows

  class Error
    class << self

      def app(e)
        G.server.logger.error "app error: #{e.inspect}"
        G.server.logger.error e.backtrace.join("\n")
        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 response(e)
        case e
        when EOFError, Errno::ECONNRESET,Errno::EPIPE,Errno::EINVAL,Errno::EBADF
          # swallow error if client shuts down one end or disconnects
        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

    end
  end
end

git clone https://yhbt.net/rainbows.git