mirror of
https://github.com/Kozea/Radicale.git
synced 2025-08-07 18:30:54 +00:00
catch server errors and return proper message
This commit is contained in:
parent
c157dd7d19
commit
88accdb672
1 changed files with 18 additions and 3 deletions
|
@ -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
|
||||||
|
|
||||||
|
@ -75,8 +77,21 @@ class ApplicationPartMkcol(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 MKCOL request on %r (type:%s): %s", path, collection_type, e, exc_info=True)
|
errno_match = re.search("\\[Errno ([0-9]+)\\]", str(e))
|
||||||
return httputils.BAD_REQUEST
|
if errno_match:
|
||||||
|
logger.error(
|
||||||
|
"Failed MKCOL request on %r (type:%s): %s", path, collection_type, 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 MKCOL request on %r (type:%s): %s", path, collection_type, e, exc_info=True)
|
||||||
|
return httputils.BAD_REQUEST
|
||||||
logger.info("MKCOL request %r (type:%s): %s", path, collection_type, "successful")
|
logger.info("MKCOL request %r (type:%s): %s", path, collection_type, "successful")
|
||||||
return client.CREATED, {}, None
|
return client.CREATED, {}, None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue