I am creating graphics and adding them to a graphics layer- this is a simplified version of what i'm doing.
symbol <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN>
type<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"picture-marker"</SPAN><SPAN class="punctuation token">,</SPAN>
url<SPAN class="punctuation token">:</SPAN> item<SPAN class="punctuation token">.</SPAN>attributes<SPAN class="punctuation token">.</SPAN>iconUrl<SPAN class="punctuation token">,</SPAN>
width<SPAN class="punctuation token">:</SPAN> sizeL<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"px"</SPAN><SPAN class="punctuation token">,</SPAN>
height<SPAN class="punctuation token">:</SPAN> sizeL<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"px"</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">var</SPAN> gO <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN>
geometry<SPAN class="punctuation token">:</SPAN> item<SPAN class="punctuation token">.</SPAN>geometry<SPAN class="punctuation token">,</SPAN>
attributes<SPAN class="punctuation token">:</SPAN> item<SPAN class="punctuation token">.</SPAN>attributes<SPAN class="punctuation token">,</SPAN>
symbol<SPAN class="punctuation token">:</SPAN> symbol
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">var</SPAN> g <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Graphic</SPAN><SPAN class="punctuation token">(</SPAN>gO<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
layer <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">GraphicsLayer</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
layer<SPAN class="punctuation token">.</SPAN>graphics <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>gO<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN>
map<SPAN class="punctuation token">.</SPAN><SPAN class="token function">add</SPAN><SPAN class="punctuation token">(</SPAN>layer<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>No error occur until after the layer is added to the map and i get cors error for the picture url:
Access to image at 'xyz.png' from origin 'http://localhost:xyz has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Then the markers are still rendered, they just are black dots:

How can i intercept the error so that I can either suppress it in the console or delete the graphics layer and reconstruct it with a working image?