Suggest there is a bad call to format/3 in your code somewhere. Often you get more info if you load library(http/http_error) in addition. That should add a backtrace to the output.
For interactive debugging, run the server with access to the toplevel and graphics (depends on platform how) and run
?- tspy(NameOfHandler).
That should open the debugger if you make the HTTP request.