0

I have the following ajaxSetup configuration:

$.ajaxSetup({
                type: 'GET',
                headers: headers,
                error: function (data, par1, par2) {
                       //Error handling code here
                    }
            });

One of the members of my team wanted to handle errors in a different way in his ajax call

$.ajax({
                url: url,
            }).done(function (result) {
                //Success code here
            }).fail(function (e) {
                //Error handling code here
            });

The problem is that the error is getting handled in both sides, error (from ajaxSetup) and fail

To avoid double handling we add an empty Error function, like this

$.ajax({
                url: url,
                error: function () {},
                }).done(function (result) {
                    //Success code here
                }).fail(function (e) {
                    //Error handling code here
                });

But it seems a bit dirty, for my mind one of them should be executed not both, so my question is how should I configure my ajaxSetup in order to avoid this "issue"?

2
  • I fear that's just the way it works. The error property will define the default action and you can add additional handling via fail(). Overwriting the property, as you are doing, is a clean way to reset the default handler. It should be possible to set it to null instead of an empty anonymous function though. Commented Nov 10, 2017 at 16:14
  • See if this helps: stackoverflow.com/a/42624210/1823841 Commented Nov 10, 2017 at 16:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.