Skip to content

Commit

Permalink
fix: handle file write errors
Browse files Browse the repository at this point in the history
  • Loading branch information
casperiv0 committed Sep 24, 2023
1 parent 6ddbcb3 commit 484ff5e
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import sharp from "sharp";
import { getLastOfArray, manyToManyHelper } from "lib/data/many-to-many";
import { allowedFileExtensions } from "@snailycad/config";
import { ExtendedBadRequest } from "~/exceptions/extended-bad-request";
import { captureException } from "@sentry/node";

@Controller("/admin/manage/cad-settings/live-map")
@ContentType("application/json")
Expand Down Expand Up @@ -98,7 +99,16 @@ export class CADSettingsLiveMapController {
const pathToClientPublicDir = `${process.cwd()}/../client/public/tiles/${
file.originalname
}.webp`;
await sharpImage.toFile(pathToClientPublicDir);

try {
await sharpImage.toFile(pathToClientPublicDir);
} catch (err) {
captureException(err);
throw new ExtendedBadRequest({
tiles:
"Unable to write to the file destination. Please make sure SnailyCAD has the correct write permissions to these files/folder",
});
}
}

return true;
Expand Down

0 comments on commit 484ff5e

Please sign in to comment.