Skip to content

Commit f69aa00

Browse files
authored
Better error handling for the URL demo (#85)
1 parent 9e1139e commit f69aa00

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

docs/src/components/CapoClient.astro

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@ import { Tabs, TabItem } from '@astrojs/starlight/components';
2323
virtualConsole = new VirtualConsole(output);
2424

2525
input.addEventListener('submit', e => {
26-
try {
27-
handleSubmit();
28-
} catch (e) {
29-
console.error('Capo error', e);
30-
}
26+
handleSubmit();
3127
e.preventDefault();
3228
return false;
3329
});
@@ -89,6 +85,11 @@ import { Tabs, TabItem } from '@astrojs/starlight/components';
8985
const proxy = new URL('https://capo.rviscomi.workers.dev/');
9086
proxy.searchParams.set('url', url);
9187
const response = await fetch(proxy);
88+
if (response.status == 502) {
89+
throw new Error(`502 Gateway Error. The URL ${url} cannot be fetched. (Possibly too many redirects)`);
90+
} else if (!response.ok) {
91+
throw new Error('Unknown error fetching the URL. Please file an issue: https://github.com/rviscomi/capo.js/issues/');
92+
}
9293
return await response.text();
9394
}
9495
</script>

0 commit comments

Comments
 (0)