Handling Ajax Post Responses

I am posting a request to a server API using basic authentication and Webix Ajax. I am using the chrome browser for testing.

When a valid post request succeeds I do not get any exception.

I have been testing what happens when authorization is incorrect.
The server is configured to send a 403 error in this test case. The problem is that it causes this exception as shown below. That exception stops any other code I have from running. I would like to be able to consume these server error responses properly without ending in an exception.

Using Chrome browser console, these are the errors listed:

POST http://192.168.1.158:8000/v1.0-beta/users/preset 403 (Forbidden)(anonymous function) @ webix_debug.js:2805
webix_debug.js:1193

Uncaught [object XMLHttpRequest]promise.finish @ webix_debug.js:1193(anonymous function) @ webix_debug.js:1276promise.thennable @ webix_debug.js:1217(anonymous function) @ webix_debug.js:1268promise.thennable @ webix_debug.js:1217promise.fire @ webix_debug.js:1233(anonymous function) @ webix_debug.js:1159

You can catch the exception in the next way

webix.ajax("some.url").then(success_handler, error_handler);

If the error handler is not provided, a code will throw an exception.
Please beware that

  • the exception is thrown only when webix_debug is used, production code (webix.js) will not throw the exception ( will trigger error_handler in any case )
  • the exception is thrown in an async way, so it must not block any other execution