File tree 2 files changed +12
-6
lines changed
projects/igniteui-angular/src/lib/icon
2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change 1
1
import { TestBed } from '@angular/core/testing' ;
2
2
import { IgxIconService } from './icon.service' ;
3
- import { HttpClientTestingModule } from '@angular/common/http/testing' ;
4
3
import { DOCUMENT } from '@angular/common' ;
5
4
6
5
import { configureTestSuite } from '../test-utils/configure-suite' ;
@@ -17,7 +16,6 @@ describe('Icon Service', () => {
17
16
18
17
beforeEach ( ( ) => {
19
18
TestBed . configureTestingModule ( {
20
- imports : [ HttpClientTestingModule ] ,
21
19
providers : [ IgxIconService ]
22
20
} ) . compileComponents ( ) ;
23
21
} ) ;
@@ -60,7 +58,7 @@ describe('Icon Service', () => {
60
58
const fontSet = 'svg-icons' ;
61
59
const iconKey = fontSet + '_' + iconName ;
62
60
63
- spyOn ( XMLHttpRequest . prototype , 'open' ) . and . callThrough ( ) ; // Jasmine 2.x
61
+ spyOn ( XMLHttpRequest . prototype , 'open' ) . and . callThrough ( ) ;
64
62
spyOn ( XMLHttpRequest . prototype , 'send' ) ;
65
63
66
64
iconService . addSvgIcon ( iconName , 'test.svg' , fontSet ) ;
Original file line number Diff line number Diff line change @@ -134,17 +134,25 @@ export class IgxIconService {
134
134
private fetchSvg ( iconName : string , url : string , fontSet : string = '' ) {
135
135
const instance = this ;
136
136
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.
137
141
httpRequest . onload = function ( event : ProgressEvent ) {
138
142
const request = event . target as XMLHttpRequest ;
139
143
if ( request . status === 200 ) {
140
144
instance . cacheSvgIcon ( iconName , request . responseText , fontSet ) ;
141
145
} 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 } ) ` ) ;
143
147
}
144
148
} ;
145
149
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
+
148
156
httpRequest . send ( ) ;
149
157
}
150
158
You can’t perform that action at this time.
0 commit comments