aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-10-11 10:35:17 -0700
committerThomas Müller <thomas.mueller@tmit.eu>2013-10-11 10:35:17 -0700
commitdc58195c7faff0285e9d4dea038331411d49dd1c (patch)
tree0a0bd49dc04b53f5e4e4e3e65e761419607692db /lib
parent067475a9071753d018f48cb42cb78d5baa13f0fc (diff)
parent3f27fefdbe1342701161bf0949dd719f34dab76d (diff)
downloadnextcloud-server-dc58195c7faff0285e9d4dea038331411d49dd1c.tar.gz
nextcloud-server-dc58195c7faff0285e9d4dea038331411d49dd1c.zip
Merge pull request #5207 from owncloud/fixing-4011-part2-master
[OC6] file upload exception handling
Diffstat (limited to 'lib')
-rw-r--r--lib/private/connector/sabre/exception/entitytoolarge.php22
-rw-r--r--lib/private/connector/sabre/exception/unsupportedmediatype.php22
-rw-r--r--lib/private/connector/sabre/file.php16
-rw-r--r--lib/public/files/entitytoolargeexception.php11
-rw-r--r--lib/public/files/invalidcontentexception.php11
-rw-r--r--lib/public/files/invalidpathexception.php11
6 files changed, 92 insertions, 1 deletions
diff --git a/lib/private/connector/sabre/exception/entitytoolarge.php b/lib/private/connector/sabre/exception/entitytoolarge.php
new file mode 100644
index 00000000000..2bda51f2f3e
--- /dev/null
+++ b/lib/private/connector/sabre/exception/entitytoolarge.php
@@ -0,0 +1,22 @@
+<?php
+
+/**
+ * Entity Too Large
+ *
+ * This exception is thrown whenever a user tries to upload a file which exceeds hard limitations
+ *
+ */
+class OC_Connector_Sabre_Exception_EntityTooLarge extends Sabre_DAV_Exception {
+
+ /**
+ * Returns the HTTP status code for this exception
+ *
+ * @return int
+ */
+ public function getHTTPCode() {
+
+ return 413;
+
+ }
+
+}
diff --git a/lib/private/connector/sabre/exception/unsupportedmediatype.php b/lib/private/connector/sabre/exception/unsupportedmediatype.php
new file mode 100644
index 00000000000..95d6a8cc651
--- /dev/null
+++ b/lib/private/connector/sabre/exception/unsupportedmediatype.php
@@ -0,0 +1,22 @@
+<?php
+
+/**
+ * Unsupported Media Type
+ *
+ * This exception is thrown whenever a user tries to upload a file which holds content which is not allowed
+ *
+ */
+class OC_Connector_Sabre_Exception_UnsupportedMediaType extends Sabre_DAV_Exception {
+
+ /**
+ * Returns the HTTP status code for this exception
+ *
+ * @return int
+ */
+ public function getHTTPCode() {
+
+ return 415;
+
+ }
+
+}
diff --git a/lib/private/connector/sabre/file.php b/lib/private/connector/sabre/file.php
index 037dba7f37b..667f7407f75 100644
--- a/lib/private/connector/sabre/file.php
+++ b/lib/private/connector/sabre/file.php
@@ -98,7 +98,21 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
throw new Sabre_DAV_Exception();
}
} catch (\OCP\Files\NotPermittedException $e) {
- throw new Sabre_DAV_Exception_Forbidden();
+ // a more general case - due to whatever reason the content could not be written
+ throw new Sabre_DAV_Exception_Forbidden($e->getMessage());
+
+ } catch (\OCP\Files\EntityTooLargeException $e) {
+ // the file is too big to be stored
+ throw new OC_Connector_Sabre_Exception_EntityTooLarge($e->getMessage());
+
+ } catch (\OCP\Files\InvalidContentException $e) {
+ // the file content is not permitted
+ throw new OC_Connector_Sabre_Exception_UnsupportedMediaType($e->getMessage());
+
+ } catch (\OCP\Files\InvalidPathException $e) {
+ // the path for the file was not valid
+ // TODO: find proper http status code for this case
+ throw new Sabre_DAV_Exception_Forbidden($e->getMessage());
}
// rename to correct path
diff --git a/lib/public/files/entitytoolargeexception.php b/lib/public/files/entitytoolargeexception.php
new file mode 100644
index 00000000000..3dff41bca02
--- /dev/null
+++ b/lib/public/files/entitytoolargeexception.php
@@ -0,0 +1,11 @@
+<?php
+/**
+ * Copyright (c) 2013 Thomas Müller <thomas.mueller@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OCP\Files;
+
+class EntityTooLargeException extends \Exception {}
diff --git a/lib/public/files/invalidcontentexception.php b/lib/public/files/invalidcontentexception.php
new file mode 100644
index 00000000000..184ec4d06d6
--- /dev/null
+++ b/lib/public/files/invalidcontentexception.php
@@ -0,0 +1,11 @@
+<?php
+/**
+ * Copyright (c) 2013 Thomas Müller <thomas.mueller@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OCP\Files;
+
+class InvalidContentException extends \Exception {}
diff --git a/lib/public/files/invalidpathexception.php b/lib/public/files/invalidpathexception.php
new file mode 100644
index 00000000000..36090ae5b48
--- /dev/null
+++ b/lib/public/files/invalidpathexception.php
@@ -0,0 +1,11 @@
+<?php
+/**
+ * Copyright (c) 2013 Thomas Müller <thomas.mueller@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OCP\Files;
+
+class InvalidPathException extends \Exception {}