5

In Angular2, suppress chrome console errors for image not found

so I have this code:

<div *ngIf="defaultImage"> 
          <img [ngStyle]="_style.img" [ngClass]="{'img-circle': circle}" [src]="getImageUrl()" (load)="onImageLoaded()" (error)="onImageError()" />
 </div>

so I have this function that looks for images online, and if an image is not found I catch the error and take action. However I am seeing an annoying console error which I would like to suppress when I am developing as its just of an annoyance, is it possible?

see below: enter image description here

regards

Sean

born2net
  • 24,129
  • 22
  • 65
  • 104
  • Does this answer your question? [Suppress Chrome 'Failed to load resource' messages in console](https://stackoverflow.com/questions/4500741/suppress-chrome-failed-to-load-resource-messages-in-console) – Bergi Jun 04 '21 at 15:04

1 Answers1

5

There is no way to suppress this error. This is browser default behavior.

If your server provides an API where you can query in advance if the file exists, that could be done. That check must not result in a 404 in case the image doesn't exist, or the check would just result in the same console log output.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567