2

Is there a way I can listen to request of type "document" and display error by catching it.

In safari i see the request under tab "Document" and in Mozilla is the request under "HTML"

enter image description here

Below is the code i have tried but it does not work

    jQuery(document).ajaxComplete(function( event, xhr, settings ) {   
    if(xhr.status == 403){
            console.error('403 response');
        }
    });

Any help on how to catch such error will be really great, Thanks.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
opensource-developer
  • 2,826
  • 4
  • 38
  • 88

1 Answers1

3

Requests of type document are not loaded through ajax, it is either the root document or else the <iframe>.

In case of root document you can't "detect" the failure, because the code to detect the failure itself is not loaded(all your logics and markup are part of this root document).

In case of <iframe> you can use onload event to detect the document load. If you are on the same domain you can simply check the relevent contents of the iframe response to detect the response code and show the message accordingly. Check this answer for other possible workarounds on iframe error detection - How to detect an error 404 in an iframe?

Yuvaraj G
  • 1,157
  • 9
  • 17