Skip to content

Commit 08a0381

Browse files
authored
[Snippets] Add error handling to rewrite-site-links.mdx (#23075)
1 parent e7f1bb6 commit 08a0381

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/content/docs/rules/snippets/examples/rewrite-site-links.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ export default {
4040
.on("img", new AttributeRewriter("src"));
4141

4242
const res = await fetch(request);
43+
if (!res.headers.has("Content-Type")) {
44+
return res;
45+
}
4346
const contentType = res.headers.get("Content-Type");
47+
if (typeof contentType !== "string") {
48+
return res;
49+
}
4450

4551
// If the response is HTML, it can be transformed with
4652
// HTMLRewriter -- otherwise, it should pass through
@@ -51,4 +57,4 @@ export default {
5157
}
5258
},
5359
};
54-
```
60+
```

0 commit comments

Comments
 (0)