【发布时间】:2017-10-22 18:20:15
【问题描述】:
我不知道以下路线哪里出错了:
(ns mds.routes.api
(:require [mds.db.core :refer [*db*] :as db]
[compojure.core :refer [defroutes POST]]
[ring.util.http-response :as response]
[clojure.walk :as walk]))
(defroutes api-routes
(POST "/student" request
(let [{body :body} request]
(let [student (walk/keywordize-keys body)]
(try
(db/create-student! student)
{:saved true
:error nil
:student student}
(catch Exception e {:saved false
:error e
:student nil})
)))))
我正在尝试返回一个带有 json 对象的响应正文,该对象类似于:
{
"saved":"true",
"error":"nil",
"student": {...}
}
但我只是得到空的响应体。 db/create-student! 调用工作正常,没有 (try) 表达式我得到 JSON 正文或 500 错误,但使用 (try) 表达式我每次都得到一个空的状态 200 响应。
如何让 (try) 表达式返回地图并将其传递给响应处理程序?
【问题讨论】:
-
能不能把不带
try的代码也加进去看看有没有其他区别?