Skip to content

Commit

Permalink
fix: throw if response status is not int
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva committed Jan 18, 2025
1 parent ada41ec commit 0f49b16
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 4 additions & 1 deletion modules/reitit-core/src/reitit/coercion.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@

(defn response-coercers [coercion responses opts]
(some->> (for [[status model] responses]
[status (response-coercer coercion model opts)])
(do
(when-not (int? status)
(throw (ex-info "Response status must be int" {:status status})))
[status (response-coercer coercion model opts)]))
(filter second) (seq) (into {})))

(defn -compile-parameters [data coercion]
Expand Down
15 changes: 14 additions & 1 deletion test/clj/reitit/ring/middleware/exception_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
[reitit.ring.coercion]
[reitit.ring.middleware.exception :as exception]
[ring.util.http-response :as http-response])
(:import (java.sql SQLException SQLWarning)))
(:import (clojure.lang ExceptionInfo)
(java.sql SQLException SQLWarning)))

(derive ::kikka ::kukka)

Expand Down Expand Up @@ -190,3 +191,15 @@
(is (contains? problems ::s/spec))
(is (contains? problems ::s/value))
(is (contains? problems ::s/problems))))))))

(deftest response-keys-test
(is (thrown-with-msg?
ExceptionInfo
#"Response status must be int"
(ring/ring-handler
(ring/router
[["/coercion"
{:middleware [reitit.ring.coercion/coerce-response-middleware]
:coercion reitit.coercion.spec/coercion
:responses {:200 {:body {:total pos-int?}}}
:handler identity}]])))))

0 comments on commit 0f49b16

Please sign in to comment.