1

As I can not comment because I am a new user, I am posting this question as separate one. This question is related to Can I catch http errors when using jQuery to modify styles?

Let us say I have a HTML5 REST based application created using Javascript, JQuery and AngularJS frameworks.

In the below snippet I have a background-image URL, if the image is not found I will get a 404 error. The snippet is dynamically generated, based on some JSON data coming from the external API. In some cases I might be having broken URLs for images.

What I am looking for is to handle all such errors globally and avoid calling one error type on each element that triggered the error.

<div style="background-image: url(http://somedomain.com/uploads/images/qq);"></div>
12
  • possible duplicate of stackoverflow.com/questions/13008150/… Commented Nov 2, 2015 at 16:05
  • Hello @juvian. The solution I am looking for is not the same as the one you suggested. I am looking for a hook or handler where I can handle all such kind of errors so that I can log them to some central server. Commented Nov 2, 2015 at 16:13
  • @Vijay (apache) servers log 404 by default Commented Nov 2, 2015 at 16:14
  • @Vijay you can just make an ajax to your sever to log the error inside the error callback Commented Nov 2, 2015 at 16:15
  • @MattBurland, I tried the below approaches, but no luck. It doesn't fire the methods at all. :) window.onerror = function () { console.log("Something gone wrong"); } and window.addEventListener("error", function (e) { console.log("Something gone wrong"); console.log(e.error.message, "from", e.error.stack); }); Commented Nov 2, 2015 at 16:26

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.