目前,当我(或者更重要的是,一个用户)在 URL 中输入我的一个剩余函数时,它可以工作,状态代码为 200。但是,如果您输入错误或拼写错误,则会生成一个 404 页面,并在通过 REST 客户端查看时显示 404 状态代码。
我不想在发送错误 URL 时收到 404 页面,而是想显示一个动态生成的 JSON 对象。
如何修复该错误处理以执行我想要的操作,是否有一个地方可以定义在特定状态代码期间应该执行的操作?
最佳答案
我对 Play Framework 不是很熟悉,但我很感兴趣。这discussion seemed at least similar to what you want :
Gaëtan Renaudeau
...
You can customize errors pages depending of the http code error (404, 500, 403, ...) by editing app/views/errors/{code}.html files where {code} is you http code. If you are using other format than html (like xml, json) you can have 404.json , 404.xml, etc...
所以,修改:
app/views/errors/404.type_of_response
希望这至少能为您指明正确的方向。
关于java - 使用 Play 框架处理 REST URL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6271053/