December 20, 2001 - Giving Friendly Error Messages | WebReference

December 20, 2001 - Giving Friendly Error Messages

Yehuda Shiran December 20, 2001
Giving Friendly Error Messages
Tips: December 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

When calling a remote Web service, errors can and will occur. The trick is how to debug the result's 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:
<BODY ID="webServiceCallerBody" onload="loadService()" STYLE="behavior:url(;background-color:peachpuff;color:brown;font-size:18">
function loadService() {
	webServiceCallerBody.onserviceavailable = enableServiceCall;  //Used for the synchronous call.
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");
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);
// -->
<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="">Interop Testing Site</A>
Notice the error in the remote service function, "echoStringg" instead of "echoString". Download You are ready to click one of the buttons and see the error message coming out of the WebService behavior.