This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-29
Channels
- # adventofcode (4)
- # beginners (113)
- # boot (165)
- # cider (192)
- # cljsrn (82)
- # clojure (148)
- # clojure-austin (6)
- # clojure-russia (22)
- # clojure-spec (45)
- # clojure-uk (19)
- # clojurescript (153)
- # core-async (5)
- # cursive (7)
- # datomic (2)
- # defnpodcast (2)
- # emacs (1)
- # hoplon (617)
- # instaparse (10)
- # lein-figwheel (19)
- # luminus (2)
- # off-topic (12)
- # om (3)
- # onyx (36)
- # pedestal (1)
- # protorepl (43)
- # re-frame (8)
- # ring (7)
- # specter (17)
- # testing (2)
- # untangled (117)
- # yada (12)
@roelof: it’s a little hard to say without knowing more about how you’ve set up your code, but in general if your flow if user requests page from you -> you make a call to the JSON API -> API result fails spec, I’d say the easiest thing to do is just render an error page instead of a “display the painting” page
Uh, I guess I’d do it from the code
Like, somewhere you have code that fires off an HTTP request, and then code that renders the page when the HTTP result comes back
I’d probably check the result when it comes back and then choose whether to render an error page or a normal page
All of that stuff could be pretty agnostic to routing, but again it’s hard to say without knowing more about your application
you can find my code as I have so far here : https://github.com/rwobben/paintings/blob/master/src/clj/paintings2/api_get.clj
I see… I think my approach would probably be here, where you get the result of (client/get url options)
: https://github.com/rwobben/paintings/blob/master/src/clj/paintings2/routes/home.clj#L26-L33
…I’d probably bind the result of (client/get)
to a local variable in that function, then run your (s/validate)
to see if it matches your spec, and then if it doesn’t call like (layout/render “incorrect-data-found.html”)
or something
You could probably generalize that out into a function eventually so you could reuse it for the detail page, maybe you’d have something like this:
(defn check-for-errors [client-get-result spec-name function-to-call-on-success]
(if (s/valid? client-get-result spec-name)
(function-to-call-on-success client-get-result)
(layout/render “error-in-json.html” …)))
(defn home-page [page]
(let [result (client/get …)]
(check-for-errors result ::page (fn [result] (-> result api/read-numbers
api/fetch-paintings-and-images-front-page))))
I’m sure there are a lot of other ways you could set it up, too. Anyways, for this stuff I don’t think you would need to mess with the routing, which just controls the association of your code and a URL.