1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 17:28:08 +00:00

Cleanup exceptions

This commit is contained in:
Julien Duponchelle 2015-04-22 10:47:49 +02:00
parent bf618d321c
commit 83f2509cfe
2 changed files with 10 additions and 4 deletions

View File

@ -15,6 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import asyncio
import aiohttp
from ...web.route import Route
from ...schemas.file import FILE_STREAM_SCHEMA
@ -28,17 +29,19 @@ class FileHandler:
description="Stream a file from the server",
status_codes={
200: "File retrieved",
404: "File doesn't exist"
404: "File doesn't exist",
409: "Can't access to file"
},
input=FILE_STREAM_SCHEMA
)
def read(request, response):
response.enable_chunked_encoding()
try:
with open(request.json.get("location"), "rb") as f:
loop = asyncio.get_event_loop()
response.content_type = "application/octet-stream"
response.set_status(200)
response.enable_chunked_encoding()
# Very important: do not send a content lenght otherwise QT close the connection but curl can consume the Feed
response.content_length = None
@ -51,4 +54,7 @@ class FileHandler:
else:
response.write(data)
except FileNotFoundError:
response.set_status(404)
raise aiohttp.web.HTTPNotFound()
except OSError as e:
raise aiohttp.web.HTTPConflict(text=str(e))