|
|
@@ -19,8 +19,10 @@
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
# along with Radicale. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
+import errno
|
|
|
import itertools
|
|
|
import posixpath
|
|
|
+import re
|
|
|
import socket
|
|
|
import sys
|
|
|
from http import client
|
|
|
@@ -264,9 +266,22 @@ class ApplicationPartPut(ApplicationBase):
|
|
|
)
|
|
|
self._hook.notify(hook_notification_item)
|
|
|
except ValueError as e:
|
|
|
- logger.warning(
|
|
|
- "Bad PUT request on %r (upload): %s", path, e, exc_info=True)
|
|
|
- return httputils.BAD_REQUEST
|
|
|
+ # return better matching HTTP result in case errno is provided and catched
|
|
|
+ errno_match = re.search("\\[Errno ([0-9]+)\\]", str(e))
|
|
|
+ if errno_match:
|
|
|
+ logger.warning(
|
|
|
+ "Failed PUT request on %r (upload): %s", path, e, exc_info=True)
|
|
|
+ errno_e = int(errno_match.group(1))
|
|
|
+ if errno_e == errno.ENOSPC:
|
|
|
+ return httputils.INSUFFICIENT_STORAGE
|
|
|
+ elif (errno_e == errno.EPERM) or (errno_e == errno.EACCES):
|
|
|
+ return httputils.FORBIDDEN
|
|
|
+ else:
|
|
|
+ return httputils.INTERNAL_SERVER_ERROR
|
|
|
+ else:
|
|
|
+ logger.warning(
|
|
|
+ "Bad PUT request on %r (upload): %s", path, e, exc_info=True)
|
|
|
+ return httputils.BAD_REQUEST
|
|
|
|
|
|
headers = {"ETag": etag}
|
|
|
return client.CREATED, headers, None
|