Properly handle failed fetches in code viewer

This commit is contained in:
Raymond Hill 2023-03-14 08:58:52 -04:00
parent 0ba5ec162b
commit c0529307fa
No known key found for this signature in database
GPG key ID: 25E1490B761470C2

View file

@ -105,9 +105,9 @@ async function fetchResource(url) {
response = await fetch(url, fetchOptions); response = await fetch(url, fetchOptions);
text = await response.text(); text = await response.text();
} catch(reason) { } catch(reason) {
text = reason; text = String(reason);
} }
let mime = response.headers.get('Content-Type') || ''; let mime = response && response.headers.get('Content-Type') || '';
mime = mime.replace(/\s*;.*$/, '').trim(); mime = mime.replace(/\s*;.*$/, '').trim();
const beautifierOptions = { const beautifierOptions = {
'end_with_newline': true, 'end_with_newline': true,