How to properly send an HTTP message to the client

后端 未结 7 1156
一生所求
一生所求 2021-02-05 00:14

I\'m working on a RESTful web service in Java. I need a good way to send error messages to the client if something\'s wrong.

According to the Javadoc, HttpServlet

7条回答
  •  一个人的身影
    2021-02-05 00:30

    I'm not quite familiar with the 'best practices' around REST. But I know the concept is based on HTTP and how it is supposed to work out naturally. So how about using a mime type and simple text inside the body for an application error, like 'application/myapp-exception' and some 'Bla bla'? You can provide a client library for that.

    I would not use HTTP response codes for application errors. Because I like to know what's failing: whether it is my application or my HTTP server.

    (I hope, I'll see some best practice advices here, too.)

提交回复
热议问题