1
0
Fork 0
mirror of https://github.com/Kozea/Radicale.git synced 2025-06-26 16:45:52 +00:00

catch server errors on put

This commit is contained in:
Peter Bieringer 2025-02-10 19:37:19 +01:00
parent 77f69f2b1e
commit f0d06cbc7d

View file

@ -19,8 +19,10 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Radicale. If not, see <http://www.gnu.org/licenses/>. # along with Radicale. If not, see <http://www.gnu.org/licenses/>.
import errno
import itertools import itertools
import posixpath import posixpath
import re
import socket import socket
import sys import sys
from http import client from http import client
@ -264,6 +266,19 @@ class ApplicationPartPut(ApplicationBase):
) )
self._hook.notify(hook_notification_item) self._hook.notify(hook_notification_item)
except ValueError as e: except ValueError as e:
# 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( logger.warning(
"Bad PUT request on %r (upload): %s", path, e, exc_info=True) "Bad PUT request on %r (upload): %s", path, e, exc_info=True)
return httputils.BAD_REQUEST return httputils.BAD_REQUEST