Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

introduce ring.middleware.stacktrace/wrap-stacktrace-log.

wrap-stacktrace-log logs formatted stacktraces to *err* and then rethrows. wrap-stacktrace now uses this to augment the returned web response. The previous web-only behavior is available with wrap-stacktrace-web.
  • Loading branch information...
commit 800cc607972a2f04c0f2426eae29356cd492187b 1 parent 531fbf4
@mmcgrana authored
Showing with 23 additions and 4 deletions.
  1. +23 −4 ring-devel/src/ring/middleware/stacktrace.clj
View
27 ring-devel/src/ring/middleware/stacktrace.clj
@@ -1,10 +1,21 @@
(ns ring.middleware.stacktrace
- "Catch exceptions and render a stacktrace for debugging."
+ "Catch exceptions and render web and log stacktraces for debugging."
(:use (hiccup core page-helpers)
(clj-stacktrace core repl)
(clojure.contrib [def :only (defvar-)])
ring.util.response))
+(defn wrap-stacktrace-log
+ "Wrap an app such that exceptions are logged to *err* and then rethrown."
+ [app]
+ (fn [req]
+ (try
+ (app req)
+ (catch Exception e
+ (let [msg (str "Exception: " (pst-str e))]
+ (.println *err* msg)
+ (throw e))))))
+
(declare css)
(defn- js-ex-response [e]
@@ -50,9 +61,9 @@
(js-ex-response e)
(html-ex-response e))))
-(defn wrap-stacktrace
- "Wrap an app such that exceptions thrown within the wrapped app are caught
- and a helpful debugging response is returned."
+(defn wrap-stacktrace-web
+ "Wrap an app such that exceptions are caught and a helpful debugging response
+ is returned."
[app]
(fn [req]
(try
@@ -60,6 +71,14 @@
(catch Exception e
(ex-response req e)))))
+(defn wrap-stacktrace
+ "Wrap an app such that exceptions are caught, a corresponding stacktrace is
+ logged to *err*, and a helpful debugging web response is returned."
+ [app]
+ (-> app
+ wrap-stacktrace-log
+ wrap-stacktrace-web))
+
(defvar- css "
/*
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
Please sign in to comment.
Something went wrong with that request. Please try again.