diff --git a/apps/files/ajax/getstoragestats.php b/apps/files/ajax/getstoragestats.php
index 4ab5b9a779c6d084e95679a55394fc0976761e00..fb7ccdc86ccb371e3c63a0b0648ea3ff4ce68766 100644
--- a/apps/files/ajax/getstoragestats.php
+++ b/apps/files/ajax/getstoragestats.php
@@ -10,4 +10,8 @@ OCP\JSON::checkLoggedIn();
 \OC::$server->getSession()->close();
 
 // send back json
-OCP\JSON::success(array('data' => \OCA\Files\Helper::buildFileStorageStatistics($dir)));
+try {
+	OCP\JSON::success(array('data' => \OCA\Files\Helper::buildFileStorageStatistics($dir)));
+} catch (\OCP\Files\NotFoundException $e) {
+	OCP\JSON::error(['data' => ['message' => 'Folder not found']]);
+}
diff --git a/lib/private/helper.php b/lib/private/helper.php
index fb4ddfae3b70d227826b7632a3261858fa79fcbd..8e9b7d3b6f32d7ade2d286593f38c846d3b2d456 100644
--- a/lib/private/helper.php
+++ b/lib/private/helper.php
@@ -905,6 +905,9 @@ class OC_Helper {
 		if (!$rootInfo) {
 			$rootInfo = \OC\Files\Filesystem::getFileInfo($path, false);
 		}
+		if (!$rootInfo instanceof \OCP\Files\FileInfo) {
+			throw new \OCP\Files\NotFoundException();
+		}
 		$used = $rootInfo->getSize();
 		if ($used < 0) {
 			$used = 0;