How to handle 403 ajax response in jQuery

ajax, error-handling, jquery

Solution

Solution: The best I found to deal with this situation per ajax request is to use statusCode method:

statusCode: {
   403: function() { 

   },
   200: function(data) {

   }
   //other codes. read the docs for more details
}

Problem

I need help handling 403 errors that come from my server in $.ajax request of jquery. It sends it as JS error because the request is forbidden but I just want the error to be a part of Ajax response, not just a JS error that fails the entire application. The 403 comes from OAuth2. If any code needs to be provided to clarify my question better, please let me know. How can I achieve that?

Original source