This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-01
Channels
- # aleph (4)
- # arachne (24)
- # beginners (231)
- # boot (4)
- # cider (63)
- # clara (36)
- # cljs-dev (57)
- # clojure (195)
- # clojure-dev (12)
- # clojure-gamedev (2)
- # clojure-greece (1)
- # clojure-italy (10)
- # clojure-poland (4)
- # clojure-spec (36)
- # clojure-uk (65)
- # clojurescript (133)
- # core-async (8)
- # core-logic (2)
- # cursive (18)
- # data-science (3)
- # datomic (58)
- # defnpodcast (3)
- # duct (2)
- # emacs (2)
- # fulcro (27)
- # graphql (3)
- # hoplon (18)
- # jobs (2)
- # jobs-discuss (10)
- # jobs-rus (1)
- # lumo (1)
- # mount (6)
- # nyc (2)
- # off-topic (27)
- # pedestal (13)
- # re-frame (71)
- # reagent (105)
- # reitit (4)
- # ring (2)
- # ring-swagger (1)
- # rum (10)
- # shadow-cljs (172)
- # spacemacs (24)
- # sql (26)
- # tools-deps (1)
- # uncomplicate (4)
- # unrepl (51)
- # vim (3)
- # yada (11)
for example, I want to ensure that all errors are serialized as json, rather than edn
all my resources specify produces: application/json, but for example schema errors will still be returned as edn
yes, yada does that on purpose -we've had a lot of problems with cheshire serializing exceptions to json - you tend to end up with cheshire serialization issues
if you look that the yada code-base, the default error interceptor chain starts by renegotiating the content-type of the response - there are some content-types that the server can produce, and you'd need to extend that to override them
it's possible if you override with your own error interceptor chain
if you look in src/yada/walk.clj
there's an example of using clojure.walk
to walk the bidi tree looking for yada resources and updating them
really, it's just a data structure which you can manipulate just like any other clojure data structure
@wdullaer I have code like this for walking:
(defn append-error-interceptor [res point & interceptors]
(update res :error-interceptor-chain
(partial mapcat (fn [i]
(if (= i point)
(concat [i] interceptors)
[i])))))
(defn private-cache-control-headers [ctx]
(assoc-in ctx [:response :headers "Cache-Control"] "no-cache"))
(defn public-cache-control-headers [ctx]
(assoc-in ctx [:response :headers "Cache-Control"] "max-age=300"))
(defn static-content [env]
["/static/"
[["" (-> (cp-resource/new-classpath-resource "public")
(assoc :id :deps.resources/static)
(yada/handler)
(yada.handler/append-interceptor sec/security-headers
(if (= :prod env)
public-cache-control-headers
identity)))]]])
(defn update-resources [routes f & args]
(walk/postwalk
(fn [x]
(if (instance? Resource x)
(resource (apply f x args))
x))
routes))
;; ... inside my routes table
(-> ... ["" [(index/index-routes postgres config)
(account/account-routes postgres email-service stripe)
(login/auth-routes postgres session-store email-service)
]]
(update-resources yada.handler/prepend-interceptor
(interceptors/begin-mock-trace))
(update-resources yada.handler/append-interceptor i/logging
(interceptors/end-mock-trace (traces/-get-tracer traces)))
(update-resources yada.handler/append-interceptor i/select-representation
csrf/check-not-forged)
(update-resources append-error-interceptor i/logging
(error-reporters/make-report-error-interceptor reporter))