
Hi, I have a handler for a post request that uses CouchDB to save a new book: newBookHandler :: ServerPart Response newBookHandler = do methodM POST decodeBody myPolicy title <- look "Title" description <- look "Description" type' <- lookRead "Type" permission <- lookRead "Permission" let author = "Asafe" liftIO $ createBook (Book title type' author description permission) ok $ toResponse ( Template.books "Your new book was just created ! Give it some love now") create is defined like that: createBook book = runCouchDB' $ newDoc db' $ toJSON book However when I perform the post request I get: Server error : Stack overflow. All works fine if I comment the line of createBook. I must be missing something because I was not able to use macid neither...

Hello, I don't see any obvious error offhand. There are two things that would interesting to try: 1. use print instead of createBook
liftIO $ print (Book title type' author description permission)
2. call createBook using static values:
liftIO $ createBook (Book "title" TheType "author" "description" ThePermissions)
(I am not sure what the types for type' and permission actually look
like, so you'll have to change that).
The aim here is to try to better isolate the location of the stack
overflow. if 'print' fails in the same way, then it is likely that
something funny is going on with the Read/Show instances for type' or
permissions. If createBook fails with the static argument, then it
could be a problem with the Json instance for book. You could test
that by doing, print (toJson $ (Book "title" ......))
As a side, note, instead of calling decodeBody all over your code, you
can just do it once at the top-level -- unless you want different
quotas for different parts of your code.
main = simpleHTTP nullConf $ (decodeBody myPolicy >> handlers)
I should probably update the crash course to emphasize that style.
- jeremy
On Sun, Jul 3, 2011 at 3:22 PM, Mister Asafe Ribeiro
Hi, I have a handler for a post request that uses CouchDB to save a new book:
newBookHandler :: ServerPart Response newBookHandler = do methodM POST decodeBody myPolicy title <- look "Title" description <- look "Description" type' <- lookRead "Type" permission <- lookRead "Permission" let author = "Asafe" liftIO $ createBook (Book title type' author description permission) ok $ toResponse ( Template.books "Your new book was just created ! Give it some love now")
create is defined like that:
createBook book = runCouchDB' $ newDoc db' $ toJSON book
However when I perform the post request I get: Server error : Stack overflow. All works fine if I comment the line of createBook. I must be missing something because I was not able to use macid neither...
_______________________________________________ web-devel mailing list web-devel@haskell.org http://www.haskell.org/mailman/listinfo/web-devel
participants (2)
-
Jeremy Shaw
-
Mister Asafe Ribeiro