0

I am with a issue on use the following code inside a route.

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

The (t/pay-billets-found) return a integer.

My routes code:

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

With give me this:

    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

Thanks.

Édipo Féderle
  • 4,169
  • 5
  • 31
  • 35

1 Answers1

1

The problem is you're returning a map {:message (str "a " (t/pay-billets-found))}

So ring assumes you're creating a proper response object with status code and what-not.

If you want to return an edn you shoud instead do:

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

If you want to properly build a ring response, either set the status and body:

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

Or use the ring.util.response helper.

guilespi
  • 4,672
  • 1
  • 15
  • 24