Better reporting of errors in PUT requests

This commit is contained in:
Unrud 2017-06-06 20:01:07 +02:00
parent e47747d4d4
commit fe97741f08

View File

@ -797,13 +797,23 @@ class Application:
tag = tags.get(content_type)
if write_whole_collection:
new_item = self.Collection.create_collection(
path, items, {"tag": tag})
try:
new_item = self.Collection.create_collection(
path, items, {"tag": tag})
except ValueError as e:
self.logger.warning(
"Bad PUT request on %r: %s", path, e, exc_info=True)
return BAD_REQUEST
else:
if tag:
parent_item.set_meta({"tag": tag})
href = posixpath.basename(path.strip("/"))
new_item = parent_item.upload(href, items[0])
try:
new_item = parent_item.upload(href, items[0])
except ValueError as e:
self.logger.warning(
"Bad PUT request on %r: %s", path, e, exc_info=True)
return BAD_REQUEST
headers = {"ETag": new_item.etag}
return client.CREATED, headers, None