Skip to content

Commit 2847ded

Browse files
Resolving 4XX errors on the CDN (#1171)
* Add icon existence checks and warnings in ComboBox, TechReport, and TableLinked components * Remove console warnings for missing icons in ComboBox, TechReport, and TableLinked components
1 parent a514c7f commit 2847ded

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

src/js/techreport/combobox.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ class ComboBox {
2929
option.dataset.key = index;
3030
option.textContent = row.technology;
3131
option.id = `${this.element.dataset.id}-${row.technology.replaceAll(' ','-')}`;
32-
const logo = document.createElement('img');
33-
logo.setAttribute('alt', '');
34-
logo.setAttribute('src', `https://cdn.httparchive.org/v1/static/icons/${icon}`);
35-
logo.setAttribute('loading', 'lazy');
36-
option.append(logo);
32+
if(icon) {
33+
const logo = document.createElement('img');
34+
logo.setAttribute('alt', '');
35+
logo.setAttribute('src', `https://cdn.httparchive.org/v1/static/icons/${icon}`);
36+
logo.setAttribute('loading', 'lazy');
37+
option.append(logo);
38+
}
3739
if(this.selected.includes(row.technology)) {
3840
option.setAttribute('aria-selected', true);
3941
}
@@ -198,12 +200,14 @@ class ComboBox {
198200
deleteSelection.dataset.name = name;
199201
deleteSelection.addEventListener('click', () => this.unselectElement(name));
200202

201-
/* Add the app logo */
202-
const appIcon = document.createElement('img');
203-
appIcon.setAttribute('src', `https://cdn.httparchive.org/v1/static/icons/${encodeURI(icon)}`);
204-
appIcon.setAttribute('alt', '');
205-
appIcon.classList.add('logo');
206-
deleteSelection.append(appIcon);
203+
if (icon) {
204+
/* Add the app logo */
205+
const appIcon = document.createElement('img');
206+
appIcon.setAttribute('src', `https://cdn.httparchive.org/v1/static/icons/${encodeURI(icon)}`);
207+
appIcon.setAttribute('alt', '');
208+
appIcon.classList.add('logo');
209+
deleteSelection.append(appIcon);
210+
}
207211

208212
/* Add the delete icon */
209213
const deleteIcon = document.createElement('img');

src/js/techreport/index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,7 @@ class TechReport {
299299
// Get the information about the selected technology
300300
getTechInfo() {
301301
const technologies = this.filters.app;
302-
const technology = technologies.join('%2C')
303-
.replaceAll(" ", "%20");
304-
302+
const technology = technologies.map(encodeURIComponent).join(',');
305303
const url = `${Constants.apiBase}/technologies?technology=${technology}`;
306304

307305
fetch(url)
@@ -315,7 +313,9 @@ class TechReport {
315313
const categories = techInfo && techInfo.category ? techInfo.category.split(', ') : [];
316314
DrilldownHeader.setCategories(categories);
317315
DrilldownHeader.setDescription(techInfo.description);
318-
DrilldownHeader.setIcon(techInfo.icon);
316+
if (techInfo.icon) {
317+
DrilldownHeader.setIcon(techInfo.icon);
318+
}
319319
});
320320
}
321321

@@ -408,7 +408,9 @@ class TechReport {
408408
const app = this.filters.app[0];
409409
const icon = data[app]?.at(-1)?.icon;
410410
DrilldownHeader.update(this.filters);
411-
DrilldownHeader.setIcon(`${encodeURI(icon)}`);
411+
if (icon) {
412+
DrilldownHeader.setIcon(`${encodeURI(icon)}`);
413+
}
412414

413415
if(data && data[app]) {
414416
UIUtils.updateReportComponents(this.sections, data, data[app], this.page, this.labels);

src/js/techreport/tableLinked.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,14 @@ class TableLinked {
106106
const wrapper = document.createElement('span');
107107
wrapper.classList.add('app-wrapper');
108108

109-
const img = document.createElement('span');
110-
const imgUrl = `https://cdn.httparchive.org/v1/static/icons/${encodeURI(technology[0]?.icon)}`;
111-
img.setAttribute('aria-hidden', 'true');
112-
img.setAttribute('style', `background-image: url(${imgUrl})`);
113-
img.classList.add('app-img');
114-
wrapper.append(img);
109+
if(technology[0]?.icon) {
110+
const img = document.createElement('span');
111+
const imgUrl = `https://cdn.httparchive.org/v1/static/icons/${encodeURI(technology[0]?.icon)}`;
112+
img.setAttribute('aria-hidden', 'true');
113+
img.setAttribute('style', `background-image: url(${imgUrl})`);
114+
img.classList.add('app-img');
115+
wrapper.append(img);
116+
}
115117

116118
const formattedApp = DataUtils.formatAppName(app);
117119
const link = document.createElement('a');

0 commit comments

Comments
 (0)