File tree Expand file tree Collapse file tree 2 files changed +12
-6
lines changed 
projects/igniteui-angular/src/lib/icon Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change 11import  {  TestBed  }  from  '@angular/core/testing' ; 
22import  {  IgxIconService  }  from  './icon.service' ; 
3- import  {  HttpClientTestingModule  }  from  '@angular/common/http/testing' ; 
43import  {  DOCUMENT  }  from  '@angular/common' ; 
54
65import  {  configureTestSuite  }  from  '../test-utils/configure-suite' ; 
@@ -17,7 +16,6 @@ describe('Icon Service', () => {
1716
1817    beforeEach ( ( )  =>  { 
1918        TestBed . configureTestingModule ( { 
20-             imports : [ HttpClientTestingModule ] , 
2119            providers : [ IgxIconService ] 
2220        } ) . compileComponents ( ) ; 
2321    } ) ; 
@@ -60,7 +58,7 @@ describe('Icon Service', () => {
6058        const  fontSet  =  'svg-icons' ; 
6159        const  iconKey  =  fontSet  +  '_'  +  iconName ; 
6260
63-         spyOn ( XMLHttpRequest . prototype ,  'open' ) . and . callThrough ( ) ;   // Jasmine 2.x 
61+         spyOn ( XMLHttpRequest . prototype ,  'open' ) . and . callThrough ( ) ; 
6462        spyOn ( XMLHttpRequest . prototype ,  'send' ) ; 
6563
6664        iconService . addSvgIcon ( iconName ,  'test.svg' ,  fontSet ) ; 
Original file line number Diff line number Diff line change @@ -134,17 +134,25 @@ export class IgxIconService {
134134    private  fetchSvg ( iconName : string ,  url : string ,  fontSet : string  =  '' )  { 
135135        const  instance  =  this ; 
136136        const  httpRequest  =  new  XMLHttpRequest ( ) ; 
137+         httpRequest . open ( 'GET' ,  url ,  true ) ; 
138+         httpRequest . responseType  =  'text' ; 
139+ 
140+         // load – when the result is ready, that includes HTTP errors like 404. 
137141        httpRequest . onload  =  function  ( event : ProgressEvent )  { 
138142            const  request  =  event . target  as  XMLHttpRequest ; 
139143            if  ( request . status  ===  200 )  { 
140144                instance . cacheSvgIcon ( iconName ,  request . responseText ,  fontSet ) ; 
141145            }  else  { 
142-                 throw  new  Error ( `Could not fetch SVG from url: ${ url }  ; error: ${ request . status }  ` ) ; 
146+                 throw  new  Error ( `Could not fetch SVG from url: ${ url }  ; error: ${ request . status }  ( ${ request . statusText } ) ` ) ; 
143147            } 
144148        } ; 
145149
146-         httpRequest . open ( 'GET' ,  url ,  true ) ; 
147-         httpRequest . responseType  =  'text' ; 
150+         // error – when the request couldn’t be made, e.g.network down or invalid URL. 
151+         httpRequest . onerror  =  function  ( event : ProgressEvent )  { 
152+             const  request  =  event . target  as  XMLHttpRequest ; 
153+             throw  new  Error ( `Could not fetch SVG from url: ${ url }  ; error status code: ${ request . status }   (${ request . statusText }  )` ) ; 
154+         } ; 
155+ 
148156        httpRequest . send ( ) ; 
149157    } 
150158
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments