Skip to content

Commit cf4049c

Browse files
committed
fix: catch fetch errors when opening device docs tab
1 parent 7a7f1ca commit cf4049c

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

src/components/device-page/tabs/Docs.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -513,19 +513,23 @@ function parseMarkdown(md: string): ReactNode[] {
513513
}
514514

515515
async function fetchMd(url: string): Promise<ReactNode[]> {
516-
const res = await fetch(url);
516+
try {
517+
const res = await fetch(url);
517518

518-
if (!res.ok) {
519-
return ["Failed to fetch"];
520-
}
519+
if (!res.ok) {
520+
return [`Connection to GitHub (${url}) is required to access device docs.`, `${res.status} - ${res.statusText}`];
521+
}
521522

522-
let text = (await res.text()).trim();
523+
let text = (await res.text()).trim();
523524

524-
if (text.startsWith("---")) {
525-
text = text.slice(text.indexOf("---", 3) + 3);
526-
}
525+
if (text.startsWith("---")) {
526+
text = text.slice(text.indexOf("---", 3) + 3);
527+
}
527528

528-
return parseMarkdown(text);
529+
return parseMarkdown(text);
530+
} catch (error) {
531+
return [`Connection to GitHub (${url}) is required to access device docs.`, `${error}`];
532+
}
529533
}
530534

531535
const DocsContent = memo(({ docsPromise }: { docsPromise: Promise<ReactNode[]> }) => {

0 commit comments

Comments
 (0)