- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2019 09:25 AM
I cannot find any documentation related to error handling when using GlideAjax. Not even documentation on the type of object that is passed to the function passed to the getXML method. Upon further inspection I did manage to find status and statusText fields, which contain 200 and OK EVEN if the server-side script throws an exception. For now the only way to capture a server-side error is to check if the answer is null, which is not documented. Besides, valid answers might be null for some apps, which would be mistakingly interpreted as a server error.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- 2,345 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2019 11:58 AM
You are right: the error handling of GlideAjax is almost undocumented.
If you want to handle Ajax error then you can do use setErrorCallback method of GlideAjax to set errorCallbackFunction property of GlideAjax object. The callback will be called by internal _handleError method if the request will be finished with the status code not equal 200. The corresponding code example will be about the following:
var ga = new GlideAjax("SomeClientCallableServerClass");
ga.addParam("sysparm_name", "someMethod");
ga.addParam("sysparm_some_param", 12345);
ga.setErrorCallback(function (reqest) {
// the code will be executed on error
});
ga.getXMLAnswer(function (answer) {
// the code will be executed on success
});
where request is the wrapper on XMLHttpRequest or new ActiveXObject("Microsoft.XMLHTTP") object.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2019 01:14 PM
I'm sorry, I used the wrong term. I meant that when throwing an exception in a server-side script (an include script in this case), the response generated by an AbstractAjaxProcessor instance has a null answer with status code 200.
I thought of a try/catch block, but it seems a little boilerplaty and could have been done on the AbstractAjaxProcessor side. The 500 segment of errors typically reports to a client that something went wrong in the server, but in this case no part of the machinery of Ajax processing in the server side acknowledges an error if an exception is thrown by the processing method and replies successfully to the client. Anyway, I'll leave this thread as documentation for current and future developers.
Thank you olegki for taking the time to understand the problem and help me 🙂.