diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-10-24 16:51:41 +1100 |
---|---|---|
committer | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-10-24 16:51:41 +1100 |
commit | c7dcccd7a1899d400bc9ddd3cdfde5db37e12bc4 (patch) | |
tree | 30aaa92a1c97040d9b923ce27e4015db0566ab96 | |
parent | TestClient middleware will now add cache misses to file for generate:client s... (diff) | |
download | server-c7dcccd7a1899d400bc9ddd3cdfde5db37e12bc4.tar.xz |
Handle fetch errors in cdn external endpoint
-rw-r--r-- | src/cdn/routes/external.ts | 3 |
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."); } |