mirror of
https://github.com/iconify/iconify.git
synced 2024-11-09 23:00:56 +00:00
Handle 404 errors in API in core by marking icons as missing
This commit is contained in:
parent
d1baf4c4c8
commit
44692efcb5
@ -194,34 +194,49 @@ function loadNewIcons(provider: string, prefix: string, icons: string[]): void {
|
||||
cachedReundancy.redundancy.query(
|
||||
item,
|
||||
api.send as QueryModuleCallback,
|
||||
(data) => {
|
||||
// Add icons to storage
|
||||
(data, error) => {
|
||||
const storage = getStorage(provider, prefix);
|
||||
try {
|
||||
const added = addIconSet(
|
||||
storage,
|
||||
data as IconifyJSON,
|
||||
'all'
|
||||
);
|
||||
if (typeof added === 'boolean') {
|
||||
|
||||
// Check for error
|
||||
if (typeof data !== 'object') {
|
||||
if (error !== 404) {
|
||||
// Do not handle error unless it is 404
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove added icons from pending list
|
||||
const pending = providerPendingIcons[prefix];
|
||||
added.forEach((name) => {
|
||||
delete pending[name];
|
||||
// Not found: mark as missing
|
||||
const t = Date.now();
|
||||
item.icons.forEach((name) => {
|
||||
storage.missing[name] = t;
|
||||
});
|
||||
|
||||
// Cache API response
|
||||
if (coreModules.cache) {
|
||||
coreModules.cache(
|
||||
provider,
|
||||
data as IconifyJSON
|
||||
} else {
|
||||
// Add icons to storage
|
||||
try {
|
||||
const added = addIconSet(
|
||||
storage,
|
||||
data as IconifyJSON,
|
||||
'all'
|
||||
);
|
||||
if (typeof added === 'boolean') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove added icons from pending list
|
||||
const pending = providerPendingIcons[prefix];
|
||||
added.forEach((name) => {
|
||||
delete pending[name];
|
||||
});
|
||||
|
||||
// Cache API response
|
||||
if (coreModules.cache) {
|
||||
coreModules.cache(
|
||||
provider,
|
||||
data as IconifyJSON
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
// Trigger update on next tick
|
||||
|
@ -22,6 +22,11 @@ describe('Testing storage', () => {
|
||||
width: 20,
|
||||
height: 16,
|
||||
});
|
||||
addIcon(storage, 'not-really-missing', {
|
||||
body: '<path d="" />',
|
||||
width: 24,
|
||||
height: 24,
|
||||
});
|
||||
|
||||
// Add another icon with reserved keyword as name
|
||||
addIcon(storage, 'constructor', {
|
||||
@ -31,17 +36,25 @@ describe('Testing storage', () => {
|
||||
rotate: 1,
|
||||
});
|
||||
|
||||
// Mark 'not-really-missing' as missing
|
||||
storage.missing['not-really-missing'] = Date.now();
|
||||
|
||||
// Add invalid icon
|
||||
addIcon(storage, 'invalid', ({} as unknown) as IconifyIcon);
|
||||
|
||||
// Should not include 'invalid'
|
||||
expect(Object.keys(storage.icons)).to.be.eql(['test', 'constructor']);
|
||||
expect(Object.keys(storage.icons)).to.be.eql([
|
||||
'test',
|
||||
'not-really-missing',
|
||||
'constructor',
|
||||
]);
|
||||
|
||||
// Test iconExists
|
||||
expect(iconExists(storage, 'test')).to.be.equal(true);
|
||||
expect(iconExists(storage, 'constructor')).to.be.equal(true);
|
||||
expect(iconExists(storage, 'invalid')).to.be.equal(false);
|
||||
expect(iconExists(storage, 'missing')).to.be.equal(false);
|
||||
expect(iconExists(storage, 'not-really-missing')).to.be.equal(true);
|
||||
|
||||
// Test getIcon
|
||||
let expected: FullIconifyIcon = {
|
||||
@ -56,16 +69,6 @@ describe('Testing storage', () => {
|
||||
};
|
||||
const icon = getIcon(storage, 'test');
|
||||
expect(icon).to.be.eql(expected);
|
||||
expected = {
|
||||
body: '<g></g>',
|
||||
width: 24,
|
||||
height: 24,
|
||||
top: 0,
|
||||
left: 0,
|
||||
hFlip: false,
|
||||
vFlip: false,
|
||||
rotate: 1,
|
||||
};
|
||||
|
||||
// Test icon mutation
|
||||
let thrown = false;
|
||||
@ -77,7 +80,18 @@ describe('Testing storage', () => {
|
||||
}
|
||||
expect(thrown).to.be.equal(true);
|
||||
|
||||
expected = {
|
||||
body: '<g></g>',
|
||||
width: 24,
|
||||
height: 24,
|
||||
top: 0,
|
||||
left: 0,
|
||||
hFlip: false,
|
||||
vFlip: false,
|
||||
rotate: 1,
|
||||
};
|
||||
expect(getIcon(storage, 'constructor')).to.be.eql(expected);
|
||||
|
||||
expect(getIcon(storage, 'invalid')).to.be.equal(null);
|
||||
expect(getIcon(storage, 'missing')).to.be.equal(null);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user