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) tag = tags.get(content_type)
if write_whole_collection: if write_whole_collection:
new_item = self.Collection.create_collection( try:
path, items, {"tag": tag}) 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: else:
if tag: if tag:
parent_item.set_meta({"tag": tag}) parent_item.set_meta({"tag": tag})
href = posixpath.basename(path.strip("/")) 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} headers = {"ETag": new_item.etag}
return client.CREATED, headers, None return client.CREATED, headers, None