-
-
Save solussd/422e9bcefc4102527b96 to your computer and use it in GitHub Desktop.
passing one or both of the optional key args results in the error: No value supplied for key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
passing one or both of the optional key args results in the error: No value supplied for key, if I don't pass the optional map-destructured args all works swell. :) | |
(defmacro def-rest-resource | |
"takes an unamed route and params as expected by defpage and a single body form, | |
optionally a map of the form {:nil-handler nil-handler-fn, :exception-handler exception-handler-fn} | |
where nil-handler-fn takes no arguments and exception-handler-fn takes an Exception as an argument" | |
[route params body & {:keys [nil-handler exception-handler] | |
:or {nil-handler #(response/status 404 {:error "no results"}) | |
exception-handler #(response/status 500 {:error (format "An error has occurred: %s" (.getMessage %))})}}] | |
`(let [response-format-fn# response/json] ; make this dependent on request accept-type in the future, json for now | |
(defpage ~route ~params | |
(try | |
(let [result# ~body] | |
(response-format-fn# (if (nil? result#) | |
(~nil-handler) | |
result#))) | |
(catch Exception exception# | |
((~exception-handler exception#))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment