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:
parent
77f69f2b1e
commit
f0d06cbc7d
1 changed files with 18 additions and 3 deletions
|
@ -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,9 +266,22 @@ class ApplicationPartPut(ApplicationBase):
|
||||||
)
|
)
|
||||||
self._hook.notify(hook_notification_item)
|
self._hook.notify(hook_notification_item)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
logger.warning(
|
# return better matching HTTP result in case errno is provided and catched
|
||||||
"Bad PUT request on %r (upload): %s", path, e, exc_info=True)
|
errno_match = re.search("\\[Errno ([0-9]+)\\]", str(e))
|
||||||
return httputils.BAD_REQUEST
|
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}
|
headers = {"ETag": etag}
|
||||||
return client.CREATED, headers, None
|
return client.CREATED, headers, None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue