error handling
This commit is contained in:
parent
11bf2e6807
commit
19bb1942d8
|
@ -81,8 +81,12 @@ class UserController {
|
|||
if (path.extname(req.file.originalname).toLowerCase() !== ".png") {
|
||||
return res.status(400).send("Only .png files are allowed!");
|
||||
}
|
||||
|
||||
try {
|
||||
const image = await Jimp.read(tempPath);
|
||||
} catch (err) {
|
||||
console.log(`Error during cape installation, ${err}`)
|
||||
return res.status(500).send("Internal server error. Please, report to the developer.")
|
||||
}
|
||||
const allowedWidths = [32, 64, 128];
|
||||
const allowedHeights = [32, 64];
|
||||
if (!allowedWidths.includes(image.bitmap.width) || !allowedHeights.includes(image.bitmap.height)) {
|
||||
|
@ -106,8 +110,13 @@ class UserController {
|
|||
if (path.extname(req.file.originalname).toLowerCase() !== ".png") {
|
||||
return res.status(400).send("Only .png files are allowed!");
|
||||
}
|
||||
|
||||
try {
|
||||
const image = await Jimp.read(tempPath);
|
||||
}
|
||||
catch (err) {
|
||||
console.log(`Error during cape installation, ${err}`)
|
||||
return res.status(500).send("Internal server error. Please, report to the developer.")
|
||||
}
|
||||
if ((image.bitmap.width != 64 || image.bitmap.height != 32) && (image.bitmap.width != 128 || image.bitmap.height != 64)) {
|
||||
return res.status(400).send('This does not look like a minecraft cape.');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue