fix(avatars) refactor preloading

Use fetch(), which gives us better control over headers.
This commit is contained in:
Saúl Ibarra Corretgé 2020-10-14 21:58:28 +02:00
parent 65a9de346f
commit a3fb996ff0
1 changed files with 11 additions and 5 deletions

View File

@ -15,10 +15,16 @@ export function preloadImage(src: string | Object): Promise<string> {
}
return new Promise((resolve, reject) => {
const image = document.createElement('img');
image.onload = () => resolve(src);
image.onerror = reject;
image.src = src;
fetch(src, { referrer: '' })
.then(response => {
if (response.ok) {
resolve(src);
} else {
reject();
}
})
.catch(e => {
reject(e);
});
});
}