diff --git a/app/controllers/contents/courseware.php b/app/controllers/contents/courseware.php
index 099a16a9a7fe280d7427e6d2e869a340289e577e..61b5115e79494e118cc6c8edc8021de0ba1fa2b7 100644
--- a/app/controllers/contents/courseware.php
+++ b/app/controllers/contents/courseware.php
@@ -22,6 +22,8 @@ class Contents_CoursewareController extends CoursewareController
         PageLayout::setTitle(_('Courseware'));
 
         $this->user = $GLOBALS['user'];
+        $this->licenses = $this->getLicenses();
+        $this->unitsNotFound = Unit::countBySql('range_id = ?', [$this->user->id]) === 0;
     }
 
     /**
@@ -38,8 +40,6 @@ class Contents_CoursewareController extends CoursewareController
         Navigation::activateItem('/contents/courseware/shelf');
         $this->user_id = $GLOBALS['user']->id;
         $this->setShelfSidebar();
-
-        $this->licenses = $this->getLicenses();
     }
 
     private function setShelfSidebar(): void
@@ -63,6 +63,14 @@ class Contents_CoursewareController extends CoursewareController
     {
         global $perm, $user;
 
+        Navigation::activateItem('/contents/courseware/courseware');
+        if ($this->unitsNotFound) {
+            PageLayout::postMessage(MessageBox::info(_('Es wurde kein Lernmaterial gefunden.')));
+            return;
+        }
+
+        $this->setCoursewareSidebar();
+
         $this->user_id = $user->id;
         /** @var array<mixed> $last */
         $last = UserConfig::get($this->user_id)->getValue('COURSEWARE_LAST_ELEMENT');
@@ -78,9 +86,6 @@ class Contents_CoursewareController extends CoursewareController
         $unit = Unit::find($unit_id);
         if (isset($unit)) {
             $this->setEntryElement('user', $unit, $last, $this->user_id);
-            Navigation::activateItem('/contents/courseware/courseware');
-            $this->licenses = $this->getLicenses();
-            $this->setCoursewareSidebar();
         }
     }
 
@@ -315,7 +320,6 @@ class Contents_CoursewareController extends CoursewareController
 
         $this->user_id = $struct->owner_id;
 
-        $this->licenses = $this->getLicenses();
 
         $this->oer_enabled = Config::get()->OERCAMPUS_ENABLED && $perm->have_perm(Config::get()->OER_PUBLIC_STATUS);
 
diff --git a/app/controllers/course/courseware.php b/app/controllers/course/courseware.php
index 89fd6e01ee327d837836bd9522cd925e86b4f656..133ebdc17509a7225ac73eff8925622bd598ee89 100644
--- a/app/controllers/course/courseware.php
+++ b/app/controllers/course/courseware.php
@@ -30,18 +30,25 @@ class Course_CoursewareController extends CoursewareController
         $this->studip_module = checkObjectModule('CoursewareModule', true);
         object_set_visit_module($this->studip_module->getPluginId());
         $this->last_visitdate = object_get_visit(Context::getId(), $this->studip_module->getPluginId());
+        $this->licenses = $this->getLicenses();
+        $this->unitsNotFound = Unit::countBySql('range_id = ?', [Context::getId()]) === 0;
     }
 
     public function index_action(): void
     {
         Navigation::activateItem('course/courseware/shelf');
-        $this->licenses = $this->getLicenses();
         $this->setIndexSidebar();
     }
 
     public function courseware_action($unit_id = null):  void
     {
         global $perm, $user;
+        Navigation::activateItem('course/courseware/unit');
+        if ($this->unitsNotFound) {
+            PageLayout::postMessage(MessageBox::info(_('Es wurde kein Lernmaterial gefunden.')));
+            return;
+        }
+        $this->setCoursewareSidebar();
 
         $this->user_id = $user->id;
         /** @var array<mixed> $last */
@@ -58,10 +65,6 @@ class Course_CoursewareController extends CoursewareController
         $unit = Unit::find($unit_id);
         if (isset($unit)) {
             $this->setEntryElement('course', $unit, $last, Context::getId());
-
-            Navigation::activateItem('course/courseware/unit');
-            $this->licenses = $this->getLicenses();
-            $this->setCoursewareSidebar();
         }
     }
 
diff --git a/app/views/contents/courseware/courseware.php b/app/views/contents/courseware/courseware.php
index bba4f1cc7ed1a9f9e7fd79fa559bd360bf20abe7..ba4a48e5467bb810f6510f0be03d00b5fcfc07c0 100644
--- a/app/views/contents/courseware/courseware.php
+++ b/app/views/contents/courseware/courseware.php
@@ -1,10 +1,12 @@
-<div
-    id="courseware-index-app"
-    entry-element-id="<?= htmlReady($entry_element_id) ?>"
-    entry-type="users"
-    entry-id="<?= htmlReady($user_id) ?>"
-    unit-id="<?= htmlReady($unit_id) ?>"
-    oer-enabled='<?= htmlReady(Config::get()->OERCAMPUS_ENABLED) ?>'
-    licenses='<?= htmlReady($licenses) ?>'
-    >
-</div>
+<? if (!$unitsNotFound): ?>
+    <div
+        id="courseware-index-app"
+        entry-element-id="<?= htmlReady($entry_element_id) ?>"
+        entry-type="users"
+        entry-id="<?= htmlReady($user_id) ?>"
+        unit-id="<?= htmlReady($unit_id) ?>"
+        oer-enabled='<?= htmlReady(Config::get()->OERCAMPUS_ENABLED) ?>'
+        licenses='<?= htmlReady($licenses) ?>'
+        >
+    </div>
+<? endif; ?>
diff --git a/app/views/course/courseware/courseware.php b/app/views/course/courseware/courseware.php
index 68503b0b029d56f0fc5ba8b6abbce3ee57e94ea5..5440c973f1405ae9b1587dfa65febed0fedd35ba 100644
--- a/app/views/course/courseware/courseware.php
+++ b/app/views/course/courseware/courseware.php
@@ -1,10 +1,12 @@
-<div
-    id="courseware-index-app"
-    entry-element-id="<?= htmlReady($entry_element_id) ?>"
-    entry-type="courses"
-    entry-id="<?= htmlReady(Context::getId()) ?>"
-    unit-id="<?= htmlReady($unit_id) ?>"
-    oer-enabled="<?= htmlReady(Config::get()->OERCAMPUS_ENABLED) ?>"
-    licenses='<?= htmlReady($licenses) ?>'
-    >
-</div>
\ No newline at end of file
+<? if (!$unitsNotFound): ?>
+    <div
+        id="courseware-index-app"
+        entry-element-id="<?= htmlReady($entry_element_id) ?>"
+        entry-type="courses"
+        entry-id="<?= htmlReady(Context::getId()) ?>"
+        unit-id="<?= htmlReady($unit_id) ?>"
+        oer-enabled="<?= htmlReady(Config::get()->OERCAMPUS_ENABLED) ?>"
+        licenses='<?= htmlReady($licenses) ?>'
+        >
+    </div>
+<? endif; ?>
diff --git a/lib/classes/JsonApi/Routes/Courseware/CoursewareInstancesHelper.php b/lib/classes/JsonApi/Routes/Courseware/CoursewareInstancesHelper.php
index a120f63e6241d7951fbb33b9adc3efaf5db4ec8f..e203fcdb1aa45ff4990ee1235c24a1d9a8597f3b 100644
--- a/lib/classes/JsonApi/Routes/Courseware/CoursewareInstancesHelper.php
+++ b/lib/classes/JsonApi/Routes/Courseware/CoursewareInstancesHelper.php
@@ -37,7 +37,9 @@ trait CoursewareInstancesHelper
             $chunks = explode('_', $rangeId);
             $courseId = $chunks[0];
             $unitId = $chunks[1] ?? null;
-
+            if ($unitId === '') {
+                throw new BadRequestException('Unit id must not be empty.');
+            }
             if ($unitId) {
                 $unit = Unit::findOneBySQL('range_id = ? AND id = ?', [$courseId, $unitId]);
             } else {
diff --git a/resources/vue/courseware-shelf-app.js b/resources/vue/courseware-shelf-app.js
index 2d31aef10dfc6ba76e17fc2cf132224c90c1afe7..f175e587a6cad5d5e670588f1d77d19fbf267310 100644
--- a/resources/vue/courseware-shelf-app.js
+++ b/resources/vue/courseware-shelf-app.js
@@ -90,4 +90,4 @@ const mountApp = async (STUDIP, createApp, element) => {
 
 };
 
-export default mountApp;
\ No newline at end of file
+export default mountApp;