summary refs log tree commit diff
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-10-24 16:51:41 +1100
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-10-24 16:51:41 +1100
commitc7dcccd7a1899d400bc9ddd3cdfde5db37e12bc4 (patch)
tree30aaa92a1c97040d9b923ce27e4015db0566ab96
parentTestClient middleware will now add cache misses to file for generate:client s... (diff)
downloadserver-c7dcccd7a1899d400bc9ddd3cdfde5db37e12bc4.tar.xz
Handle fetch errors in cdn external endpoint
-rw-r--r--src/cdn/routes/external.ts3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/cdn/routes/external.ts b/src/cdn/routes/external.ts
index 32979a59..08e6b164 100644
--- a/src/cdn/routes/external.ts
+++ b/src/cdn/routes/external.ts
@@ -74,11 +74,14 @@ router.get("/resize/:url", async (req: Request, res: Response) => {
 	let buffer, response;
 	try {
 		response = await fetch(url, DEFAULT_FETCH_OPTIONS);
+		if (response.status !== 200) throw "e";		// lol super gross
 		buffer = await response.buffer();
 	} catch (e) {
 		throw new HTTPError("Couldn't fetch website");
 	}
 
+	if (buffer.length == 0) throw new HTTPError("Website response was empty.");
+
 	if (response.headers.get("content-type")?.indexOf("image") === -1) {
 		throw new HTTPError("Content type is not image.");
 	}