Skip to content

correct usage of :ataraxy.error/failed-spec  #3

Description

@zerg000000

Here is a working example start from [module.ataraxy 0.17]. May I know using :example instead of :my.handler/example is intentional or not?

config.edn

{:duct.module/ataraxy
 {[:get "/example" {body :params}] [:example body]}
 :duct.router/ataraxy
 {:handlers {:ataraxy.error/failed-spec #ig/ref :my.handler/error}}
 :my.handler/error {}}

my.handler/example.clj

(defmethod ig/init-key :my.handler/example [_ options]
  (fn [{[_ body] :ataraxy/result}]
    [::response/ok (io/resource "my/handler/example/example.html")]))

(defmethod ataraxy/result-spec :example [_]
  (s/tuple any? :my.spec/example))

my.handler/error.clj

(defmethod ig/init-key :my.handler/error [_ options]
  (fn [{[_ error] :ataraxy/result}]
    (let [messages (map f/format
                        (-> error :clojure.spec.alpha/problems))]
      [::response/bad-request {:messages messages}])))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions