开发者

REST URL error handling using the Play framework

开发者 https://www.devze.com 2023-03-11 13:09 出处:网络
Currently when I (or more importantly, a user) type in one of my rest functions into the URL, it works, 开发者_开发问答with the 200 status code. But if you type a wrong one or mispell it, a 404 page i

Currently when I (or more importantly, a user) type in one of my rest functions into the URL, it works, 开发者_开发问答with the 200 status code. But if you type a wrong one or mispell it, a 404 page is generated, with a 404 status code when looking at it through a REST client.

Instead of getting a 404 page when the bad URL is sent, I would instead like to display a dynamically generated JSON object.

How do I fix that error handling to do what I want, Is there a place where I can define what should be done during a particular status code?


I am not very familiar with the Play Framework, but I was interested. This 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...

So, modify:

app/views/errors/404.type_of_response

Hopefully this at least points you in the right direction.

0

精彩评论

暂无评论...
验证码 换一张
取 消