Skip to content

Commit

Permalink
Use console.warn instead of console.error when we catch a failed fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
eyeseast committed Dec 5, 2024
1 parent d534f50 commit d4a2cf2
Show file tree
Hide file tree
Showing 20 changed files with 66 additions and 66 deletions.
2 changes: 1 addition & 1 deletion src/lib/api/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export async function setOrg(
[CSRF_HEADER_NAME]: csrf_token,
},
method: "PATCH",
}).catch(console.error);
}).catch(console.warn);

return getApiResponse<User>(resp);
}
Expand Down
18 changes: 9 additions & 9 deletions src/lib/api/addons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export async function getAddons(
endpoint.searchParams.set(key, String(value));
});
const resp = await fetch(endpoint, { credentials: "include" }).catch(
console.error,
console.warn,
);

return getApiResponse<Page<AddOnListItem>>(resp);
Expand Down Expand Up @@ -83,7 +83,7 @@ export async function getEvent(
const endpoint = new URL(`addon_events/${id}/?expand=addon`, BASE_API_URL);

const resp = await fetch(endpoint, { credentials: "include" }).catch(
console.error,
console.warn,
);

return getApiResponse<Event>(resp);
Expand All @@ -108,7 +108,7 @@ export async function history(
}

const resp = await fetch(endpoint, { credentials: "include" }).catch(
console.error,
console.warn,
);

return getApiResponse<Page<Run>>(resp);
Expand All @@ -127,7 +127,7 @@ export async function scheduled(
}

const resp = await fetch(endpoint, { credentials: "include" }).catch(
console.error,
console.warn,
);

return getApiResponse<Page<Event>>(resp);
Expand All @@ -154,7 +154,7 @@ export async function dispatch(
Referer: APP_URL,
},
body: JSON.stringify(payload),
}).catch(console.error);
}).catch(console.warn);

return getApiResponse<Run | Event, ValidationError>(resp);
}
Expand All @@ -178,7 +178,7 @@ export async function update(
Referer: APP_URL,
},
body: JSON.stringify(payload),
}).catch(console.error);
}).catch(console.warn);

return getApiResponse<Event, ValidationError>(resp);
}
Expand Down Expand Up @@ -208,7 +208,7 @@ export async function dismiss(
Referer: APP_URL,
},
body: JSON.stringify({ dismissed: true }),
}).catch(console.error);
}).catch(console.warn);

return getApiResponse<Run>(resp);
}
Expand All @@ -234,7 +234,7 @@ export async function cancel(
[CSRF_HEADER_NAME]: csrf_token,
Referer: APP_URL,
},
}).catch(console.error);
}).catch(console.warn);

return getApiResponse<null>(resp);
}
Expand Down Expand Up @@ -268,7 +268,7 @@ export async function rate(
Referer: APP_URL,
},
body: JSON.stringify({ rating: value }),
}).catch(console.error);
}).catch(console.warn);

return getApiResponse<Run>(resp);
}
Expand Down
6 changes: 3 additions & 3 deletions src/lib/api/collaborators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export async function add(
Referer: APP_URL,
},
method: "POST",
}).catch(console.error);
}).catch(console.warn);

return getApiResponse<ProjectUser, ValidationError>(resp);
}
Expand Down Expand Up @@ -67,7 +67,7 @@ export async function update(
Referer: APP_URL,
},
method: "PATCH",
}).catch(console.error);
}).catch(console.warn);

return getApiResponse<ProjectUser, ValidationError>(resp);
}
Expand All @@ -91,7 +91,7 @@ export async function remove(
Referer: APP_URL,
},
method: "DELETE",
}).catch(console.error);
}).catch(console.warn);

return getApiResponse<null, any>(resp);
}
36 changes: 18 additions & 18 deletions src/lib/api/documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export async function search(
}

const resp = await fetch(endpoint, { credentials: "include" }).catch(
console.error,
console.warn,
);

return getApiResponse<DocumentResults, null>(resp);
Expand All @@ -102,7 +102,7 @@ export async function searchWithin(
}
}
const resp = await fetch(endpoint, { credentials: "include" }).catch(
console.error,
console.warn,
);
return getApiResponse<Highlights, null>(resp);
}
Expand All @@ -127,7 +127,7 @@ export async function get(
endpoint.searchParams.set("expand", expand.join(","));

const resp = await fetch(endpoint, { credentials: "include" }).catch(
console.error,
console.warn,
);

return getApiResponse<Document, null>(resp);
Expand All @@ -151,7 +151,7 @@ export async function list(
}

const resp = await fetch(endpoint, { credentials: "include" }).catch(
console.error,
console.warn,
);

return getApiResponse<DocumentResults>(resp);
Expand All @@ -176,12 +176,12 @@ export async function text(
try {
url = await getPrivateAsset(url, fetch);
} catch (e) {
console.error(e);
console.warn(e);
return empty;
}
}

const resp = await fetch(url).catch(console.error);
const resp = await fetch(url).catch(console.warn);
if (!resp || isErrorCode(resp.status)) {
return empty;
}
Expand All @@ -204,7 +204,7 @@ export async function textPositions(
try {
url = await getPrivateAsset(url);
} catch (e) {
console.error(e);
console.warn(e);
return [];
}
}
Expand All @@ -214,7 +214,7 @@ export async function textPositions(
if (!resp || isErrorCode(resp.status)) return [];
return resp.json();
} catch (e) {
console.error(e);
console.warn(e);
return [];
}
}
Expand Down Expand Up @@ -242,7 +242,7 @@ export async function create(
Referer: APP_URL,
},
body: JSON.stringify(doc),
}).catch(console.error);
}).catch(console.warn);

return getApiResponse<Document, unknown>(resp);
}
Expand Down Expand Up @@ -290,7 +290,7 @@ export async function process(
Referer: APP_URL,
},
body: JSON.stringify(documents),
}).catch(console.error);
}).catch(console.warn);

return getApiResponse<null, unknown>(resp);
}
Expand All @@ -317,7 +317,7 @@ export async function cancel(
[CSRF_HEADER_NAME]: csrf_token,
Referer: APP_URL,
},
}).catch(console.error);
}).catch(console.warn);

return getApiResponse<null, any>(resp);
}
Expand All @@ -339,7 +339,7 @@ export async function destroy(
[CSRF_HEADER_NAME]: csrf_token,
Referer: APP_URL,
},
}).catch(console.error);
}).catch(console.warn);

return getApiResponse<null, any>(resp);
}
Expand All @@ -366,7 +366,7 @@ export async function destroy_many(
[CSRF_HEADER_NAME]: csrf_token,
Referer: APP_URL,
},
}).catch(console.error);
}).catch(console.warn);

return getApiResponse<null, unknown>(resp);
}
Expand Down Expand Up @@ -397,7 +397,7 @@ export async function edit(
Referer: APP_URL,
},
body: JSON.stringify(data),
}).catch(console.error);
}).catch(console.warn);

return getApiResponse<Document, ValidationError>(resp);
}
Expand Down Expand Up @@ -426,7 +426,7 @@ export async function edit_many(
Referer: APP_URL,
},
body: JSON.stringify(documents),
}).catch(console.error);
}).catch(console.warn);

return getApiResponse<DocumentResults>(resp);
}
Expand All @@ -453,7 +453,7 @@ export async function add_tags(
Referer: APP_URL,
},
body: JSON.stringify(data),
}).catch(console.error);
}).catch(console.warn);

return getApiResponse<Data, any>(resp);
}
Expand Down Expand Up @@ -513,8 +513,8 @@ export async function assetUrl(
// assets still processing are in private storage until finished
if (document.access !== "public" || String(asset_url).startsWith(DC_BASE)) {
asset_url = await getPrivateAsset(asset_url, fetch).catch((e) => {
console.error(e);
console.error(asset_url.href);
console.warn(e);
console.warn(asset_url.href);
return asset_url;
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/api/flatpages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function get(

const endpoint = new URL("flatpages" + path, BASE_API_URL);
const resp = await fetch(endpoint, { credentials: "include" }).catch(
console.error,
console.warn,
);

return getApiResponse<Flatpage>(resp);
Expand Down
10 changes: 5 additions & 5 deletions src/lib/api/notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function list(
endpoint.searchParams.set("expand", DEFAULT_EXPAND);

const resp = await fetch(endpoint, { credentials: "include" }).catch(
console.error,
console.warn,
);

return getApiResponse<Page<Note>>(resp);
Expand All @@ -56,7 +56,7 @@ export async function get(
endpoint.searchParams.set("expand", DEFAULT_EXPAND);

const resp = await fetch(endpoint, { credentials: "include" }).catch(
console.error,
console.warn,
);

return getApiResponse<Note>(resp);
Expand Down Expand Up @@ -84,7 +84,7 @@ export async function create(
Referer: APP_URL,
},
method: "POST",
}).catch(console.error);
}).catch(console.warn);

return getApiResponse<Note, ValidationError>(resp);
}
Expand Down Expand Up @@ -113,7 +113,7 @@ export async function update(
Referer: APP_URL,
},
method: "PATCH",
}).catch(console.error);
}).catch(console.warn);

return getApiResponse<Note, ValidationError>(resp);
}
Expand All @@ -140,7 +140,7 @@ export async function remove(
Referer: APP_URL,
},
method: "DELETE",
}).catch(console.error);
}).catch(console.warn);

return getApiResponse<null>(resp);
}
Expand Down
Loading

0 comments on commit d4a2cf2

Please sign in to comment.