1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-10 04:32:35 +01:00

Handle fetch errors in cdn external endpoint

This commit is contained in:
Madeline 2022-10-24 16:51:41 +11:00
parent 0f9951bb0e
commit c7dcccd7a1
No known key found for this signature in database
GPG Key ID: 1958E017C36F2E47

View File

@ -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.");
}