Use response.ok instead of just status 200 (#999)

This commit is contained in:
Fábio Rosado
2022-11-30 13:17:48 +00:00
committed by GitHub
parent dc1d583791
commit b31428006c

View File

@@ -8,7 +8,8 @@ import { FetchError, ErrorCode } from "./exceptions";
*/
export async function robustFetch(url: string, options?: RequestInit): Promise<Response> {
const response = await fetch(url, options);
if (response.status !== 200) {
// Note that response.ok is true for 200-299 responses
if (!response.ok) {
const errorMsg = `Fetching from URL ${url} failed with error ${response.status} (${response.statusText}).`;
switch(response.status) {
case 404: