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:
parent
0f9951bb0e
commit
c7dcccd7a1
@ -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.");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user