docs.intersystems.com
Home  /  Application Development: Additional Options  /  Web Services Quick Start Tutorial  /  Web Service Error Handling in InterSystems IRIS  /  Error Handling Logic


Web Services Quick Start Tutorial
Error Handling Logic
[Back]  [Next] 
InterSystems: The power behind what matters   
Search:  


You can use the ApplicationError method to generate a SOAP fault at every point where your Web Service might generate an error. For example, currently the SOAPTutorial.SOAPService GetContact method ends normally, by returning “”, if there is no Contact with an ID value matching the client's input. In this situation, the method should properly generate an error.
Modify the SOAPTutorial.SOAPService GetContact so that it generates a SOAP fault. Here is the new method. Notice that it passes appropriate values for faultcode and detail to ApplicationError.
Method GetContact(id As %String) As SOAPTutorial.Contact [ WebMethod ]
{
 if ##class(SOAPTutorial.Contact).%ExistsId(id) {
  return ##class(SOAPTutorial.Contact).%OpenId(id)
 }
 else {
  do ..ApplicationError("ContactNotFound", 
                                 "Contact with id "_id_" could not be found!")
 }
}