catch os errors
This commit is contained in:
@@ -18,7 +18,9 @@
|
|||||||
# 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 posixpath
|
import posixpath
|
||||||
|
import re
|
||||||
import socket
|
import socket
|
||||||
from http import client
|
from http import client
|
||||||
|
|
||||||
@@ -71,7 +73,20 @@ class ApplicationPartMkcalendar(ApplicationBase):
|
|||||||
try:
|
try:
|
||||||
self._storage.create_collection(path, props=props)
|
self._storage.create_collection(path, props=props)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
logger.warning(
|
# return better matching HTTP result in case errno is provided and catched
|
||||||
"Bad MKCALENDAR request on %r: %s", path, e, exc_info=True)
|
errno_match = re.search("\\[Errno ([0-9]+)\\]", str(e))
|
||||||
return httputils.BAD_REQUEST
|
if errno_match:
|
||||||
|
logger.error(
|
||||||
|
"Failed MKCALENDAR request on %r: %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 in [errno.EPERM, errno.EACCES]:
|
||||||
|
return httputils.FORBIDDEN
|
||||||
|
else:
|
||||||
|
return httputils.INTERNAL_SERVER_ERROR
|
||||||
|
else:
|
||||||
|
logger.warning(
|
||||||
|
"Bad MKCALENDAR request on %r: %s", path, e, exc_info=True)
|
||||||
|
return httputils.BAD_REQUEST
|
||||||
return client.CREATED, {}, None
|
return client.CREATED, {}, None
|
||||||
|
|||||||
Reference in New Issue
Block a user