"error" block of Jester does not work when using custom routers. I'm not sure what is wrong. Could anyone advise me how to catch exceptions with custom routers?
import htmlgen, jester
routes:
get "/":
raise(newException(OSError, "exception"))
error Exception:
resp h1("An exception occurred")
-> "An exception occurred" is shown
import asyncdispatch, jester, os, strutils, htmlgen
router myrouter:
get "/":
raise(newException(OSError, "exception"))
error Exception:
resp h1("An exception occurred")
proc main() =
let port = Port(5000)
let settings = newSettings(port=port)
var jester = initJester(myrouter, settings=settings)
jester.serve()
when isMainModule:
main()
-> the default stack trace generated by Jester is shownLooks like a bug, double check you've got the latest jester version via nimble install jester@#head and if the issue is still there then report it in the GitHub repo.
Note that in your example a custom router doesn't make sense, why are you doing it this way?
I opened an issue in the GitHub repo as it was reproduced at #head. https://github.com/dom96/jester/issues/211
The above code is a minimal one to demonstrate the problem. I'm coding API generator for Jester, and I need to define some routers in separated files, then I found the issue. The below are sample codes (it's still WIP). https://github.com/hokamoto/openapi-generator/tree/nimforum5196/samples/server/petstore/nim-jester-server