clojurecompojure

Why do I get java.lang.exception unrecognized body on routes with friend/authenticated as a wrapper?


I am using friend along with friend-redis-token where sessions are stored in redis for my compojure application.

for a route which is something like..

  (POST "/service/logout" {headers :headers}
          (session/invalidate-session
           (headers "x-auth-token")))

Everything works fine!

As soon as I wrap the handler with friend/authenticated. I get the error

:WARN:oejs.AbstractHttpConnection:/service/logout
java.lang.Exception: Unrecognized body: ...

I am using the following middlewares:

                        (jsonware/wrap-json-body)
                        (jsonware/wrap-json-params)
                        (jsonware/wrap-json-response)

to convert everything in body to JSON, could that bve conflicting with friend ?


Solution

  • I believe the problem might be with the return value of session/invalidate-session. So try something like this:

    (POST "/service/logout" {headers :headers}
      (do (session/invalidate-session
            (headers "x-auth-token"))
          ""))
    

    Compojure tries to be clever about doing the right thing with the return values of routes and this often ends up causing problems such as this.