Skip to content

Commit ac9ac13

Browse files
committed
Treat redirects as failures
1 parent c826628 commit ac9ac13

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/cnames.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,20 @@ const testUrl = async url => {
157157
try {
158158
resp = await fetch(url, { signal: controller.signal });
159159
} catch (err) {
160-
if (err.name === "AbortError") return "Failed due to time out after 5s"
161-
return `Failed during request with error '${err}'`
160+
if (err.name === "AbortError") return "Failed due to time out after 5s";
161+
return `Failed during request with error '${err}'`;
162162
} finally {
163163
clearTimeout(timer);
164164
}
165165
if (!resp.ok) {
166-
return `Failed with status code '${resp.status} ${resp.statusText}'`
166+
return `Failed with status code '${resp.status} ${resp.statusText}'`;
167+
}
168+
if (resp.redirected) {
169+
return `Failed due to automatic redirect to '${resp.url}'`;
167170
}
168171
const text = await resp.text();
169172
if (text.toLowerCase().trim() === "") {
170-
return `Failed with empty return body (status '${resp.status} ${resp.statusText}')`
173+
return `Failed with empty return body (status '${resp.status} ${resp.statusText}')`;
171174
}
172175
};
173176

0 commit comments

Comments
 (0)