December 20, 2001 - Giving Friendly Error Messages
December 20, 2001 Giving Friendly Error Messages Tips: December 2001
Yehuda Shiran, Ph.D.
|
errorDetail
object, to find as many clues as possible regarding the source of the problem. The string
property is a human-readable fault code. If the code
property gives a very brief machine-readable message, the string
property gives a much more elaborate message that makes sense to the user. For example, try calling a Web service with a wrong function name. You will receive an errorDetail
object where string is "Error is Invalid argument."
Here is the html page with the error:
<HTML>
<BODY ID="webServiceCallerBody" onload="loadService()" STYLE="behavior:url(webservice.htc);background-color:peachpuff;color:brown;font-size:18">
<SCRIPT LANGUAGE="JavaScript">
<!--
function loadService() {
webServiceCallerBody.onserviceavailable = enableServiceCall; //Used for the synchronous call.
webServiceCallerBody.useService("https://soap.bluestone.com:80/interop/EchoService/EchoService.wsdl","echo");
}
function callAsynch() {
iCallID = webServiceCallerBody.echo.callService(handleResult, "echoStringg", "Asynchronous Call");
}
function callSynch() {
var co = webServiceCallerBody.createCallOptions();
co.funcName = "echoStringg";
co.async = false;
var oResult = webServiceCallerBody.echo.callService(co, "Synchronous Call");
handleResult(oResult);
}
function enableServiceCall() {
b2.disabled = false;
}
function handleResult(res) {
if (!res.error) {
alert("Successful call. Result is " + res.value);
}
else {
alert("Unsuccessful call. Error is " + res.errorDetail.string);
}
}
// -->
</SCRIPT>
<HR><H4>Calls to an echo service</H4><HR><BR><BR>
<BUTTON ID="b1" onclick="callAsynch()">Call Asynchronously</BUTTON><BR><BR>
<BUTTON ID="b2" onclick="callSynch()" disabled>Call Synchronously</BUTTON><BR><BR><BR><BR>
<A HREF="https://www.xmethods.net/ilab/">Interop Testing Site</A>
</BODY>
</HTML>
Notice the error in the remote service function, "echoStringg"
instead of "echoString"
. Download webservice.htc. You are ready to click one of the buttons and see the error message coming out of the WebService behavior.