Hide/change console error message

Asked

Viewed 768 times

0

I try to take for example a file that does not exist on my site, as:

try {
    $.getScript('app/controllers/arquivo-errado.js', function(){});
} catch (e) {
    // caso de erro
}

The error is returned in the console:

GET URL...app/controllers/file-wrong.js? _=1484154145345 404 (Not Found)

I want to know how can exchange or hide this error, for example exchange it for an error 'File does not exist', or without showing the error.

1 answer

1


I do not think it is possible to delete or replace this native 404 message from the browser. But:

1) You can add a default message by adding a callback .fail to the method:

$.getScript('app/controllers/arquivo-errado.js')
  .done(function( script, textStatus ) {
    console.log("Arquivo carregado com sucesso :)");
  })
  .fail(function( jqxhr, settings, exception ) {
    console.log("Não foi possível carregar o arquivo :(");
  });

2) or make a kind of proxy file that passes the js file to the client, but, in case you don’t find it, just renders a 200 code with no content. This way, the browser does not understand 404 and does not show the error. Just an idea.

  • I managed to get around the error in another way, having a file of routes, but I tested here with the proxy file and ran good too, thanks

Browser other questions tagged

You are not signed in. Login or sign up in order to post.