File tree Expand file tree Collapse file tree 3 files changed +17
-2
lines changed
Expand file tree Collapse file tree 3 files changed +17
-2
lines changed Original file line number Diff line number Diff line change 4949(defmethod ig /init-key ::bad-request [_ response]
5050 (make-handler (assoc response :status 400 )))
5151
52+ (defmethod ig /init-key ::bad-request-malformed [_ response]
53+ (let [handler (make-handler (assoc response :status 400 ))]
54+ (fn [_ _ request]
55+ (handler request))))
56+
5257(defmethod ig /init-key ::not-found [_ response]
5358 (make-handler (assoc response :status 404 )))
5459
Original file line number Diff line number Diff line change 123123 (merge-with deep-merge a b)
124124 b))
125125
126- (defmethod ig /init-key ::format [_ options]
127- #(mm/wrap-format % (deep-merge mc/default-options options)))
126+ (defmethod ig /init-key ::format [_ {:keys [malformed-handler]
127+ :as options
128+ :or {malformed-handler
129+ (ig/ref :duct.handler.static/bad-request-malformed )}}]
130+ #(mm/wrap-exception
131+ (mm/wrap-format % (deep-merge mc/default-options options))
132+ malformed-handler))
Original file line number Diff line number Diff line change 11(ns duct.module.web
22 (:require [clojure.java.io :as io]
33 [clojure.string :as str]
4+ [cheshire.core :as cheshire]
45 [duct.core :as core]
56 [duct.core.env :as env]
67 [duct.core.merge :as merge]
7071
7172(def ^:private base-config
7273 {:duct.handler.static/bad-request (plaintext-response " Bad Request" )
74+ :duct.handler.static/bad-request-malformed (plaintext-response " Bad Request Malformed" )
7375 :duct.handler.static/not-found (plaintext-response " Not Found" )
7476 :duct.handler.static/method-not-allowed (plaintext-response " Method Not Allowed" )
7577 :duct.handler.static/internal-server-error (plaintext-response " Internal Server Error" )
8082
8183(def ^:private api-config
8284 {:duct.handler.static/bad-request {:body ^:displace {:error :bad-request }}
85+ :duct.handler.static/bad-request-malformed {:body (cheshire/generate-string {:error " Malformed request body" })
86+ :headers {" Content-Type" " application/json" }}
8387 :duct.handler.static/not-found {:body ^:displace {:error :not-found }}
8488 :duct.handler.static/method-not-allowed {:body ^:displace {:error :method-not-allowed }}
8589 :duct.handler.static/internal-server-error
113117
114118(defn- site-config [project-ns]
115119 {:duct.handler.static/bad-request (html-response error-400)
120+ :duct.handler.static/bad-request-malformed (html-response error-400)
116121 :duct.handler.static/not-found (html-response error-404)
117122 :duct.handler.static/method-not-allowed (html-response error-405)
118123 :duct.handler.static/internal-server-error (html-response error-500)
You can’t perform that action at this time.
0 commit comments