0

Is there any way to prevent http errors to appear in the console?

E.g. when I try to geo locate the user ip I call

$.get( "https://freegeoip.net/json/", function( data ) { 
  alert( "Load was performed." );
});

I sometimes get a 503 and cannot catch it before it is displayed to my users in the console.

Try / catch does not seem work here.

Obiwahn
  • 2,677
  • 2
  • 26
  • 36

1 Answers1

0

I will suggest to use $.ajax instead of $.get for better customization

Jquery $.get

$.get('https://freegeoip.net/json/', function(data){ 
    alert( "Load was performed." );
}).fail(function() {
    alert('woops'); // or your error handling code
});

Jquery $.ajax

$.ajax({
    url: 'https://freegeoip.net/json/',
    type: 'GET',
    success: function(data){ 
        alert( "Load was performed." );
    },
    error: function(data) {
         alert('woops!');// or your error handling code
    }
});
rrk
  • 15,677
  • 4
  • 29
  • 45
Satish Kumar sonker
  • 1,250
  • 8
  • 15