diff --git a/src/functions/errors.js b/src/functions/errors.js
new file mode 100644
index 0000000000000000000000000000000000000000..d6b16ad468aebc8e3ca98874a635fc784752bd1c
--- /dev/null
+++ b/src/functions/errors.js
@@ -0,0 +1,10 @@
+class CustomError extends Error {
+  constructor(message, statusCode) {
+    super(message);
+    this.name = "CustomError";
+    this.statusCode = statusCode;
+    Error.captureStackTrace(this, this.constructor);
+  }
+}
+
+module.exports = CustomError;
diff --git a/src/functions/helperFunctions.js b/src/functions/helperFunctions.js
index 456398402c2de52219c9a63cd392ea83b171edac..c5ddd712468663c4254c7dce7b66f2fe05bcbddb 100644
--- a/src/functions/helperFunctions.js
+++ b/src/functions/helperFunctions.js
@@ -10,6 +10,7 @@ const {
   killDockerContainer,
 } = require("../docker/dockerManager");
 const { v4: uuidv4 } = require("uuid");
+const CustomError = require("./errors.js");
 
 const fillDockerJS = async (code) => {
   const filePath = path.resolve(__dirname, "../../docker.js");
@@ -204,6 +205,11 @@ const scaleOut = async (id) => {
     );
     const customCodes = await getCustomCodes();
     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));
     scaledCode.isScaled = id;
     scaledCode.id = uuidv4();
diff --git a/src/routes/deployRouter.js b/src/routes/deployRouter.js
index c0d86da10254e905f38b86b32780c4f1f6a3edfc..1d4f75284c7605e0663ef8dca401abab3d6ba85b 100644
--- a/src/routes/deployRouter.js
+++ b/src/routes/deployRouter.js
@@ -57,7 +57,11 @@ deployRouter.post("/scaleOut", async (req, res) => {
     res.status(200).json({ message: "Scale Out erfolgreich" });
   } catch (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" });
+    }
   }
 });