【问题标题】:response map is nil compojure响应图是 nil compojure
【发布时间】:2018-02-28 03:46:59
【问题描述】:

我什么都不懂。 当我大摇大摆地做curl -X GET --header 'Accept: application/json' 'http://localhost:3000/api/hello' 时,我得到了一个很好的答案{"result":1}。 但是,当我尝试类似:http://localhost:3000/api/hello?criteria=drf 时,服务器会给我java.lang.NullPointerException: Response map is nil。我很确定它不是零,因为我的{"result":1} 仍然出现在屏幕上。 但是在第一个错误之后,每个GET /hello 请求,没有任何查询参数,在服务器端给出一个错误,同时仍然给客户端正确的答案?

并且我需要重新启动服务器才能使错误停止。哪个有效,直到第一个带有查询参数的请求......

(ns swag.handler
  (:require [compojure.api.sweet :refer :all]
            [ring.util.http-response :refer :all]
            [clojure.java.jdbc :as j]
            [clojure.core.match :as match]
            [clojure.spec.alpha :s s]
            )
(def app
  (api
    {:swagger
     {:ui "/"
      :spec "/swagger.json"
      :data {:info {:title "Trash"
                    :description "Compojure Api example"}
             :tags [{:name "api", :description "some apis"}]}}}

    (context "/api" []
      :tags ["api"]

      (GET "/plus" []
        :return {:result Long}
        :query-params [x :- Long, y :- Long]
        :summary "adds two numbers together"
        (ok {:result (+ x y)}))

      (GET "/hello" []
        :query-params [& z]
        (let [criteria (:criteria z) values (:date z)]
          (println z)
          (ok {:result 1})))
))
  )

【问题讨论】:

  • 不会为“/hello”添加 GET?解决问题?似乎服务器已经崩溃,因此变得无响应,但浏览器仍在以某种方式通过其缓存做出响应。
  • 我无法在 compojure-api 示例中使用您的 def 重现此错误:github.com/metosin/compojure-api/tree/master/examples/simple。带参数的 Get 有效。

标签: clojure compojure ring


【解决方案1】:

如果您收到此消息,请在浏览器中检查 favicon.ico 请求。

这可能会触发响应映射为空,因为没有配置路由来处理它。

【讨论】:

  • 这个问题已经 3 岁了。我也放弃了 clojure 因为不可调试
  • 我添加了以供将来参考,因为我刚刚遇到了同样的问题 :)
  • 最简单的修复方法是什么?
【解决方案2】:

我们的问题是我们需要在给我们这个错误的端点上尾随 /s(在我们调试时正在查看您的 q,但刚刚解决了)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-01
    • 2018-03-23
    • 2017-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-05
    • 2013-06-10
    相关资源
    最近更新 更多