From 83f2509cfe778b69a1aed2475d58047f81317e17 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Wed, 22 Apr 2015 10:47:49 +0200 Subject: [PATCH] Cleanup exceptions --- gns3server/handlers/api/file_handler.py | 12 +++++++++--- gns3server/main.py | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/gns3server/handlers/api/file_handler.py b/gns3server/handlers/api/file_handler.py index 1dc2e31b..e705ffc2 100644 --- a/gns3server/handlers/api/file_handler.py +++ b/gns3server/handlers/api/file_handler.py @@ -15,6 +15,7 @@ # along with this program. If not, see . 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)) + diff --git a/gns3server/main.py b/gns3server/main.py index 2ced1294..7404365c 100644 --- a/gns3server/main.py +++ b/gns3server/main.py @@ -175,7 +175,7 @@ def main(): Project.clean_project_directory() - executor = concurrent.futures.ThreadPoolExecutor(max_workers=100) # We allow 100 parallel executors + executor = concurrent.futures.ThreadPoolExecutor(max_workers=100) # We allow 100 parallel executors loop = asyncio.get_event_loop().set_default_executor(executor) CrashReport.instance()