Skip to content

Commit 0d85508

Browse files
committed
fix(icon): Requested changes applied #4971
1 parent b013347 commit 0d85508

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

projects/igniteui-angular/src/lib/icon/icon.service.spec.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { TestBed } from '@angular/core/testing';
22
import { IgxIconService } from './icon.service';
3-
import { HttpClientTestingModule } from '@angular/common/http/testing';
43
import { DOCUMENT } from '@angular/common';
54

65
import { 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);

projects/igniteui-angular/src/lib/icon/icon.service.ts

+11-3
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)