开发者

Returning REST 400-Bad Request with additional information

开发者 https://www.devze.com 2023-03-10 10:24 出处:网络
Hey, I have a REST based server, and in some cases I want to return a failure code (400 for example), B开发者_JS百科UT, I wish to add additional URL.

Hey, I have a REST based server, and in some cases I want to return a failure code (400 for example), B开发者_JS百科UT, I wish to add additional URL. Something like - "failure, but here's what you can do now.." Is there any good convention to do so? Is it even a good idea to return error with additional information?

Thanks, Udi


It is always a good idea to return additional information in an error message. The HTTP spec itself says so: "Except when responding to a HEAD request, the server SHOULD include an entity containing an explanation of the error situation, and whether it is a temporary or permanent condition. These status codes are applicable to any request method. User agents SHOULD display any included entity to the user."

One thing to watch out for: some versions of Internet Explorer will not show the user your additional error information if it is not a certain number of bytes. Make sure your response entities for error messages are at least 512 bytes to be sure.

0

精彩评论

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