路径内的功能问题(Clojure / Compojure)

时间:2014-10-27 22:49:07

标签: clojure compojure

我遇到了在路由中使用以下代码的问题。

(str "Size " (t/pay-billets-found)) ;-> "Size 2"

(t / pay-billets-found)返回一个整数。

我的路线代码:

(defroutes app-routes
(POST "/upload" []
     {:message (str "a " (t/pay-billets-found))}))

给我这个:

    clojure.lang.ExceptionInfo: clj-http: status 500
                    client.clj:171 clj-http.client/wrap-exceptions[fn]
                    client.clj:522 clj-http.client/wrap-accept[fn]
                    client.clj:536 clj-http.client/wrap-accept-encoding[fn]
                    client.clj:512 clj-http.client/wrap-content-type[fn]
                    client.clj:683 clj-http.client/wrap-form-params[fn]
                    client.clj:707 clj-http.client/wrap-nested-params[fn]
                    client.clj:624 clj-http.client/wrap-method[fn]
                   cookies.clj:121 clj-http.cookies/wrap-cookies[fn]
                      links.clj:50 clj-http.links/wrap-links[fn]
                    client.clj:726 clj-http.client/wrap-unknown-host[fn]
                    client.clj:847 clj-http.client/put
                   RestFn.java:439 clojure.lang.RestFn.invoke
                       core.clj:33 tbbrr.core/pay-billet
                       core.clj:58 tbbrr.core/pay-billets-found[fn]
                       core.clj:56 tbbrr.core/pay-billets-found[fn]
                   LazySeq.java:40 clojure.lang.LazySeq.sval
                   LazySeq.java:49 clojure.lang.LazySeq.seq
               ChunkedCons.java:59 clojure.lang.ChunkedCons.chunkedNext
                      core.clj:667 clojure.core/chunk-next
                 protocols.clj:101 clojure.core.protocols/fn
                  protocols.clj:19 clojure.core.protocols/fn[fn]
                  protocols.clj:31 clojure.core.protocols/seq-reduce
                  protocols.clj:54 clojure.core.protocols/fn
                  protocols.clj:13 clojure.core.protocols/fn[fn]
                     core.clj:6289 clojure.core/reduce
                     core.clj:6341 clojure.core/into
                       core.clj:56 tbbrr.core/pay-billets-found
                     server.clj:36 tbbrr.server/fn
                       core.clj:94 compojure.core/make-route[fn]
                       core.clj:40 compojure.core/if-route[fn]
                       core.clj:25 compojure.core/if-method[fn]
                      core.clj:107 compojure.core/routing[fn]
                     core.clj:2515 clojure.core/some
                      core.clj:107 compojure.core/routing
                   RestFn.java:139 clojure.lang.RestFn.applyTo
                      core.clj:626 clojure.core/apply
                      core.clj:112 compojure.core/routes[fn]
             keyword_params.clj:32 ring.middleware.keyword-params/wrap-keyword-params[fn]
              nested_params.clj:75 ring.middleware.nested-params/wrap-nested-params[fn]
                     params.clj:58 ring.middleware.params/wrap-params[fn]
          multipart_params.clj:107 ring.middleware.multipart-params/wrap-multipart-params[fn]
                      flash.clj:31 ring.middleware.flash/wrap-flash[fn]
                    session.clj:85 ring.middleware.session/wrap-session[fn]
                      Var.java:379 clojure.lang.Var.invoke
                     reload.clj:18 ring.middleware.reload/wrap-reload[fn]
                 stacktrace.clj:17 ring.middleware.stacktrace/wrap-stacktrace-log[fn]
                 stacktrace.clj:80 ring.middleware.stacktrace/wrap-stacktrace-web[fn]
                      jetty.clj:18 ring.adapter.jetty/proxy-handler[fn]
                  (Unknown Source)        ring.adapter.jetty.proxy$org.eclipse.jetty.server.handler.AbstractHandler$ff19274a.handle
           HandlerWrapper.java:116 org.eclipse.jetty.server.handler.HandlerWrapper.handle
                   Server.java:359 org.eclipse.jetty.server.Server.handle
   AbstractHttpConnection.java:483 org.eclipse.jetty.server.AbstractHttpConnection.handleRequest
   AbstractHttpConnection.java:920 org.eclipse.jetty.server.AbstractHttpConnection.headerComplete
   AbstractHttpConnection.java:982 org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete
               HttpParser.java:642 org.eclipse.jetty.http.HttpParser.parseNext
               HttpParser.java:235 org.eclipse.jetty.http.HttpParser.parseAvailable
       AsyncHttpConnection.java:82 org.eclipse.jetty.server.AsyncHttpConnection.handle
    SelectChannelEndPoint.java:628 org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle
     SelectChannelEndPoint.java:52 org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run
         QueuedThreadPool.java:608 org.eclipse.jetty.util.thread.QueuedThreadPool.runJob
         QueuedThreadPool.java:543 org.eclipse.jetty.util.thread.QueuedThreadPool$3.run
                   Thread.java:744 java.lang.Thread.run

感谢。

1 个答案:

答案 0 :(得分:1)

问题是您要返回地图{:message (str "a " (t/pay-billets-found))}

因此,环假设您正在使用状态代码和什么不创建正确的响应对象。

如果你想要回复edn,请改为:

(pr-str {:message (str "a " (t/pay-billets-found))})

如果要正确构建响铃响应,请设置状态和正文:

{:status 200 :body (pr-str {:message (str "a " (t/pay-billets-found))})}

或使用ring.util.response帮助器。