5 Replies - 587 Views - Last Post: 02 August 2014 - 08:57 AM

#1 Blindman67  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 127
  • View blog
  • Posts: 562
  • Joined: 15-March 14

Stopping image 404 (Not Found) from reporting in the console.

Posted 01 August 2014 - 06:35 PM

I have a image loading system that uses fall back directories if the image is not found in the primary directory, it will check the next until found. Eventual if the image required is not found a default image is put in place that is just a one pixel black image. All works just fine apart from the console which is full of "Failed to load resource: the server responded with a status of 404 (Not Found)" which is all good and fine for me, I can filter them out using the console filters but i do not want them to appear on the clients console, nor do i want to block all thrown errors from being seen.

I am using the onerror to do the directory sniffing on the images. i have tried using event.preventDefault to stop the error being reported, but no luck. I have also tried "try catch" on loading code but it does not see it as a thrown error.

The app is designed to be stand alone so I can not get help from the server, the images are stored on the clients file system.

Does anyone know of a way to suppress console errors by type from within javascript without having to manipulate the DEV tools console filters?

Is This A Good Question/Topic? 0
  • +

Replies To: Stopping image 404 (Not Found) from reporting in the console.

#2 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 725
  • View blog
  • Posts: 3,161
  • Joined: 03-December 12

Re: Stopping image 404 (Not Found) from reporting in the console.

Posted 01 August 2014 - 06:44 PM

Would this work,

if (typeof console == 'undefined') {

    var console = {};

    console.log = function(msg) {

        return false;

   };

}

Was This Post Helpful? 0
  • +
  • -

#3 Blindman67  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 127
  • View blog
  • Posts: 562
  • Joined: 15-March 14

Re: Stopping image 404 (Not Found) from reporting in the console.

Posted 01 August 2014 - 07:40 PM

The message does not seem to come through the console.log method, but you have given me an idea.. need to look up the console API to see if it can be done.
Was This Post Helpful? 0
  • +
  • -

#4 Blindman67  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 127
  • View blog
  • Posts: 562
  • Joined: 15-March 14

Re: Stopping image 404 (Not Found) from reporting in the console.

Posted 01 August 2014 - 08:35 PM

I have used this to do what i want in part. Not a perfect solution by any means, but it does get rid of ugly looking pointless error reports, still lets through any throws that block the app, and still displays important message logs as I develop and beta test. There is one problem in that it will delete all web worker errors and event driven errors as they do not block the main app loop.

But would still prefer to just trap the 404 error.

My solution.
console.oldLog = console.log;  // save old log function
console.msgList = [];          // array to keep all log messages
console.log = function(msg){   // override the existing log function
    console.msgList.push(msg);  // save the message
    console.clear();           // clear the console.
    var len = console.msgList.length;
    for(var i = 0; i < len; i++){   // display all logged message.
        console.oldLog(console.msgList[i]);   // using old log function
    }
}

// at set points I now call
console.reset = function(){
    console.clear();           // clear the console.
    console.msgList = [];
}


Was This Post Helpful? 0
  • +
  • -

#5 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3550
  • View blog
  • Posts: 10,319
  • Joined: 08-June 10

Re: Stopping image 404 (Not Found) from reporting in the console.

Posted 02 August 2014 - 07:38 AM

do you request the images directly or via AJAX? for the latter you could do a HEAD request and check for a 404 header.
Was This Post Helpful? 0
  • +
  • -

#6 Blindman67  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 127
  • View blog
  • Posts: 562
  • Joined: 15-March 14

Re: Stopping image 404 (Not Found) from reporting in the console.

Posted 02 August 2014 - 08:57 AM

It needs to have full functionality while offline, so AJAX would be a last ditch solution to this problem, which really is just a cosmetic one. I just hate seeing red in my console, they look like thrown errors, but are not.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1