This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-09-12
Channels
- # announcements (2)
- # bangalore-clj (4)
- # beginners (97)
- # calva (57)
- # cider (24)
- # clj-kondo (1)
- # cljdoc (4)
- # cljs-dev (8)
- # cljsrn (6)
- # clojure (27)
- # clojure-berlin (7)
- # clojure-dev (95)
- # clojure-europe (16)
- # clojure-italy (15)
- # clojure-losangeles (9)
- # clojure-nl (8)
- # clojure-spec (10)
- # clojure-uk (29)
- # clojurescript (25)
- # clojutre (2)
- # clr (6)
- # cursive (33)
- # datomic (20)
- # dirac (1)
- # duct (9)
- # fulcro (2)
- # graalvm (18)
- # jobs (5)
- # jobs-discuss (19)
- # nrepl (4)
- # nyc (1)
- # off-topic (18)
- # pathom (15)
- # re-frame (22)
- # reagent (4)
- # reitit (1)
- # rewrite-clj (9)
- # spacemacs (2)
- # xtdb (12)
Curious: how do you model your domain layer? What does it return? How do you interpret that into http status codes?
@dominicm we generally have two paths...
in the first a domain fn returns a promise of a result type when successful, and an errored promise wrapping a [tag data]
variant in the ex-info when it fails
in the second it returns a promise of [tag data]
when successful too, and the same errored promise with [tag data]
in the ex-info when it fails
tag
gets mapped to an http status code either by default or by a map of {tag status}
declared on the resource
(and by promise here i mean manifold/Deferred
)
they are namespaced keywords
this is from a couple of namespaces, so the aliases don't line up, but here's an example: https://gist.github.com/mccraigmccraig/7a27330dc57ec4bf37b9743cf6708d98
api-method-fn
dispatches a multimethod with the resource key and passes the (merged) params from yada, then uses the tag-status-map
(if provided, otherwise the default) to convert the result into an http response
the end result is that in the simplest case successful calls get a 200 and any errors a 500, but should finer control be appropriate then the domain layer returns something that makes sense in its world, which then gets mapped to an http status
are what all names for http ?
the domain-layer response tags ?
Are the domain tags all e.g. Unauthorized which maps directly to http, or do you have increased/decreased granularity?
entirely up to a particular resource implementation. some resources return partial success type tags which all get an http 200, some resources have various failures which all map to a 500. generally the domain layer returns something that makes sense for it regardless of the transport
and in the unanticipated failure case (i.e. an errored promise carrying an exception payload), the exception gets mapped to a generic failure tag and result in a 500, unless overridden
ah, so you do have more nuance than http in some cases. That's what I'd figured would happen.
yes - it's relatively rare though. most resources just use the default success=200/failure=500
(crosscutting stuff like auth is done in an interceptor and precedes this flow)
Yeah, it's an interesting decision where to do auth. Http seems to want you to do it quite early. So domain layers tend to assume authenticated, and sometimes authorized.
yep: we assume authenticated, and have a walker which applies an authentication interceptor to authenticated resources. authorization hasn't found a declarative form yet and is generally done ad-hoc inside the domain layer