开发者

Catch and Show an error from a WCF service call in javascript

开发者 https://www.devze.com 2022-12-28 06:33 出处:网络
I\'m calling a WCF service through javascript and right now it\'s not showing any errors that might occur on the service side to the user.I have the code below and am looking for a better way to infor

I'm calling a WCF service through javascript and right now it's not showing any errors that might occur on the service side to the user. I have the code below and am looking for a better way to inform the user an error has occured, including the call stack and error message if possible.

The service itself throws a FaultException if an error has occured. However, I want to catch that error in the javascript call and show it to the user.

Here is the js code to call the service

function Save() {
    var saveInfo = $("._saveInfo").val()

    app.namspace.interfacetoservice.Save(
        saveInfo,
        function(results) {
            if (results == true) {
                window.close();
            }
            else {
                alert("error saving");
            }
  开发者_如何学Python      }
    );
}

Thanks for the help!


app.namspace.interfacetoservice.Save( 
    saveInfo, 
    function(results) { 
        if (results == true) { 
            window.close(); 
        } 
        else { 
            alert("error saving"); 
        } 
    },
    function(error) { 
        alert(error.get_StackTrace());
    });

Thanks if anyone was looking into this, I was unaware of the second callback that happens for errors.

0

精彩评论

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

关注公众号