From 36879403d25aa10f7143d3520855e3d121f9ea6f Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 26 Feb 2015 15:58:45 +0800 Subject: [PATCH 1/3] Bring error in request ExceptionInfo. --- src/fnhouse/middleware.clj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fnhouse/middleware.clj b/src/fnhouse/middleware.clj index f07f3d0..c3ce07d 100644 --- a/src/fnhouse/middleware.clj +++ b/src/fnhouse/middleware.clj @@ -60,7 +60,8 @@ {:type :coercion-error :schema schema :data data - :context context})) + :context context + :error error})) res)))))) (defn request-walker From a6827230658ddd9efb6664131dc9628b1f29f2c4 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Fri, 10 Apr 2015 15:47:09 +0800 Subject: [PATCH 2/3] add custom to request --- src/fnhouse/handlers.clj | 5 +++-- src/fnhouse/middleware.clj | 5 +++-- src/fnhouse/schemas.clj | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/fnhouse/handlers.clj b/src/fnhouse/handlers.clj index 6388e85..c1f3c91 100644 --- a/src/fnhouse/handlers.clj +++ b/src/fnhouse/handlers.clj @@ -142,7 +142,7 @@ (letk [[method path] (path-and-method var) [{doc ""} {responses {}}] (meta var) [{resources {}} {request {}}] (pfnk/input-schema @var) - [{uri-args s/Any} {query-params s/Any} {body nil}] request] + [{uri-args s/Any} {query-params s/Any} {body nil} {custom nil}] request] (let [source-map (source-map var) explicit-uri-args (dissoc (default-map-schema uri-args) s/Keyword) raw-declared-args (routes/uri-arg-ks path) @@ -155,7 +155,8 @@ :body body :uri-args (merge (map-from-keys (constantly String) declared-args) - explicit-uri-args)} + explicit-uri-args) + :custom custom} :responses responses :resources resources diff --git a/src/fnhouse/middleware.clj b/src/fnhouse/middleware.clj index c3ce07d..1c323cf 100644 --- a/src/fnhouse/middleware.clj +++ b/src/fnhouse/middleware.clj @@ -34,6 +34,7 @@ {:uri-args [coerce/string-coercion-matcher] :query-params [coerce/string-coercion-matcher] :body [coerce/json-coercion-matcher] + :custom [coerce/string-coercion-matcher] :response []}) (s/defn coercing-walker @@ -54,7 +55,7 @@ (if-let [error (utils/error-val res)] (throw (ex-info (format "Request: [%s]
==> Error: [%s]
==> Context: [%s]" - (pr-str (select-keys request [:uri :query-string :body])) + (pr-str (select-keys request [:uri :query-string :body :custom])) (pr-str error) context) {:type :coercion-error @@ -68,7 +69,7 @@ "Given a custom input coercer, compile a function for coercing and validating requests (uri-args, query-params, and body)." [input-coercer handler-info] - (let [request-walkers (for-map [k [:uri-args :query-params :body] + (let [request-walkers (for-map [k [:uri-args :query-params :body :custom] :let [schema (safe-get-in handler-info [:request k])] :when schema] k diff --git a/src/fnhouse/schemas.clj b/src/fnhouse/schemas.clj index 2aa501a..12ef441 100644 --- a/src/fnhouse/schemas.clj +++ b/src/fnhouse/schemas.clj @@ -61,7 +61,8 @@ :request {:uri-args {s/Keyword Schema} :query-params fnk-schema/InputSchema - :body (s/maybe Schema)} + :body (s/maybe Schema) + :custom (s/maybe Schema)} :responses {(s/named s/Int "status code") (s/named Schema "response body schema")} From ce73f8bc19c16c9a0f621bf180317db6a93fd7e6 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Fri, 10 Apr 2015 15:48:41 +0800 Subject: [PATCH 3/3] rename project --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.clj b/project.clj index fc134c1..807697a 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject prismatic/fnhouse "0.1.2-SNAPSHOT" +(defproject tiensonqin/fnhouse-hacks "0.1.2-SNAPSHOT" :description "Transform lightly-annotated functions into a full-fledged web service" :license {:name "Eclipse Public License - v 1.0" :url "http://www.eclipse.org/legal/epl-v10.html"