I am running out of ideas while looking for an error in my code. I am using Obelisk with Servant
and servant-reflex
to have my XMLHttpRequests generated automatically.
I just added a route to my api, like this:
type RoutesAdmin =
AuthRequired "jwt" :> "journal" :> ReqBody '[JSON] (UTCTime, UTCTime) :> Get '[JSON] [Journal]
… to realize that, when testing in my browser, the server responds with “bad request”. Checking the payload of the request (also in the web browser), I find nothing. So it looks like, indeed, the request is malformed.
But how?
This is the code where servant-reflex generates my client code:
getJournalAll
:: SupportsServantReflex t m
=> Dynamic t (Either Text (CompactJWT, Text))
-> Dynamic t (Either Text (UTCTime, UTCTime))
-> Event t ()
-> m (Event t (ReqResult () [Journal]))
((postConfigNew :<|> getDocDEPatternAll :<|> getDocDEPattern :<|> getDictDE :<|> getDictDENumbers) :<|> (getJournalAll) :<|> (postAuthenticate :<|> postAuthNew :<|> postDoesUserExist :<|> postLogout) :<|> ((postAliasRename :<|> getAliasAll :<|> postAliasSetDefault) :<|> (getAppState :<|> postAppState)) :<|> (postEventViewPage :<|> postEventStageCompleted))
= client (Proxy :: Proxy RoutesApi)
(Proxy :: Proxy (m :: * -> *))
(Proxy :: Proxy ())
(constDyn (BasePath "/"))
The fact that my codes typechecks and then generats a “bad request” really seems weird. It doesn’t seem like I have a lot of room for error.
- a type mismatch causes a compiler error
- omitting arguments in the client or the backend code caues a compile error
- having a function argument not ready, is reflected by the
Either
type and doesn’t cause a “bad request”
It seems like the client builds the request code, ignoring the request body.
My custom-made combinator AuthRequired
could be the culprit, but I use other routes with AuthRequired
and ReqBody
just fine.
Any idea how to debug this?