Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly report ring request parameters #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/circleci/rollcage/ring_middleware.clj
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
(ns circleci.rollcage.ring-middleware
(:require [circleci.rollcage.core :as rollcage]))

(def ^:const request-and-wrap-parameter-keys
"selector for keys provided by ring's request map and by ring's wrap-parameter middleware"
[:http-method :query-string :query-params :form-params :params])

(defn wrap-rollbar [handler rollcage-client]
(if-not rollcage-client
handler
(fn [req]
(try
(handler req)
(catch Exception e
(rollcage/error rollcage-client e (select-keys req [:uri]))
(rollcage/error rollcage-client e {:url (:uri req)
:params (select-keys req request-and-wrap-parameter-keys)})
(throw e))))))
7 changes: 5 additions & 2 deletions test/circleci/rollcage/test_ring_middleware.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
dummy-ring-handler (fn [_]
(throw error)
{:status 200})
dummy-request {:uri "/" :params {}}]
dummy-request {:http-method :get
:uri "/search"
:query-string "q=clojure"}]
(testing "Reports rollbars when rollcage-client is truthy"
(let [dummy-rollcage-client {}
wrapped-handler (middleware/wrap-rollbar dummy-ring-handler
Expand All @@ -20,7 +22,8 @@
(catch Exception e
e))]
(is (= result error))
(is (= [[dummy-rollcage-client error {:uri "/"}]]
(is (= [[dummy-rollcage-client error {:url "/search" :params {:http-method :get
:query-string "q=clojure"}}]]
(->> rollcage/error
bond/calls
(map :args))))))))
Expand Down