Skip to content

Commit 37e3c09

Browse files
authored
[Snippets] Add error handling to rewrite-site-links.mdx
1 parent ab9095e commit 37e3c09

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,14 @@ 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+
}
46+
4347
const contentType = res.headers.get("Content-Type");
48+
if (typeof contentType !== "string") {
49+
return res;
50+
}
4451

4552
// If the response is HTML, it can be transformed with
4653
// HTMLRewriter -- otherwise, it should pass through
@@ -51,4 +58,4 @@ export default {
5158
}
5259
},
5360
};
54-
```
61+
```

0 commit comments

Comments
 (0)