about summary refs log tree commit homepage
path: root/lib/rainbows/error.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-11-26 14:09:45 -0800
committerEric Wong <normalperson@yhbt.net>2009-11-26 14:19:04 -0800
commit5868eeecb2fbc85f3e4fabf3d16f27d259491c0d (patch)
tree21746be61158f9c177bc8e2600d7922cdedc7ce1 /lib/rainbows/error.rb
parent278d9d5a7f3d2dc3c6563af1584b5e773e08073d (diff)
downloadrainbows-5868eeecb2fbc85f3e4fabf3d16f27d259491c0d.tar.gz
Make sure app errors get logged correctly, and we no longer
return a 500 response when a client EOFs the write end (but not
the read end) of a connection.
Diffstat (limited to 'lib/rainbows/error.rb')
-rw-r--r--lib/rainbows/error.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/rainbows/error.rb b/lib/rainbows/error.rb
new file mode 100644
index 0000000..89b1187
--- /dev/null
+++ b/lib/rainbows/error.rb
@@ -0,0 +1,34 @@
+# -*- 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
+        else
+          app(e)
+          Const::ERROR_500_RESPONSE
+        end
+      end
+
+    end
+  end
+end