Skip to content
Snippets Groups Projects
Commit ded8d853 authored by Robin Leber's avatar Robin Leber
Browse files

Scale out error handling

parent a139c55f
No related branches found
No related tags found
No related merge requests found
class CustomError extends Error {
constructor(message, statusCode) {
super(message);
this.name = "CustomError";
this.statusCode = statusCode;
Error.captureStackTrace(this, this.constructor);
}
}
module.exports = CustomError;
...@@ -10,6 +10,7 @@ const { ...@@ -10,6 +10,7 @@ const {
killDockerContainer, killDockerContainer,
} = require("../docker/dockerManager"); } = require("../docker/dockerManager");
const { v4: uuidv4 } = require("uuid"); const { v4: uuidv4 } = require("uuid");
const CustomError = require("./errors.js");
const fillDockerJS = async (code) => { const fillDockerJS = async (code) => {
const filePath = path.resolve(__dirname, "../../docker.js"); const filePath = path.resolve(__dirname, "../../docker.js");
...@@ -204,6 +205,11 @@ const scaleOut = async (id) => { ...@@ -204,6 +205,11 @@ const scaleOut = async (id) => {
); );
const customCodes = await getCustomCodes(); const customCodes = await getCustomCodes();
const codeToScale = customCodes.find((code) => code.id === id); const codeToScale = customCodes.find((code) => code.id === id);
if (!codeToScale) {
throw new CustomError("Need to code first!", 500);
} else if (!codeToScale.isDeployed) {
throw new CustomError("Need to deploy first!", 500);
}
const scaledCode = JSON.parse(JSON.stringify(codeToScale)); const scaledCode = JSON.parse(JSON.stringify(codeToScale));
scaledCode.isScaled = id; scaledCode.isScaled = id;
scaledCode.id = uuidv4(); scaledCode.id = uuidv4();
......
...@@ -57,7 +57,11 @@ deployRouter.post("/scaleOut", async (req, res) => { ...@@ -57,7 +57,11 @@ deployRouter.post("/scaleOut", async (req, res) => {
res.status(200).json({ message: "Scale Out erfolgreich" }); res.status(200).json({ message: "Scale Out erfolgreich" });
} catch (e) { } catch (e) {
console.error(e); console.error(e);
res.status(500).json({ message: "Scale Out fehlgeschlagen" }); if (e.name === "CustomError") {
res.status(500).json({ message: e.message });
} else {
res.status(500).json({ message: "Scale Out fehlgeschlagen" });
}
} }
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment