Fork me on GitHub

@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


oke, and can I do the render from the code or only from a routes function ?


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


im still working on the input validation with spec


I see… I think my approach would probably be here, where you get the result of (client/get url options):


…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


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.