Exception Handling in REST services

Source: Internet
Author: User

In the rest service, if the service side generates exception information, whether it is a business exception or a system exception, if the exception is thrown directly in the client browser, it is not possible to get the details of the exception, only get a statecode Internal Server error error, as follows:

http/1.1  Internal Server errorcontentContent-type:text/xml; charset=utf-8server:microsoft-httpapi/2.013 :£ º  GMT<error><message>an Error has occurred.</message ></Error>

If you need to get detailed exception information on the server side of the client, you need to define the exception information as follows:

var New Httpresponsemessage (httpstatuscode.forbidden) {    new stringcontent ("notallowed To delete this resource"),    "Forbidden"};     Throw New Httpresponseexception (RESP);

Throwing httpresponseexception can be captured and processed in the client (browser, debugging tools such as Fiddler), as follows:

http/1.1403  forbiddencontentContent-type:text/plain; charset=utf-8server:microsoft-httpapi/2.013 :+: This resource

Exception Handling in REST services

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.