mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 11:18:11 +00:00
Cleanly forward exception from compute to controller
This commit is contained in:
parent
d8bdd16e13
commit
972cbd0594
@ -305,16 +305,24 @@ class Compute:
|
||||
body = body.decode()
|
||||
|
||||
if response.status >= 300:
|
||||
# Try to decode the GNS3 error
|
||||
try:
|
||||
msg = json.loads(body)["message"]
|
||||
except (KeyError, json.decoder.JSONDecodeError):
|
||||
msg = body
|
||||
|
||||
if response.status == 400:
|
||||
raise aiohttp.web.HTTPBadRequest(text="Bad request {} {}".format(url, body))
|
||||
elif response.status == 401:
|
||||
raise aiohttp.web.HTTPUnauthorized(text="Invalid authentication for compute {}".format(self.id))
|
||||
elif response.status == 403:
|
||||
raise aiohttp.web.HTTPForbidden(text="Forbidden {} {}".format(url, body))
|
||||
raise aiohttp.web.HTTPForbidden(text=msg)
|
||||
elif response.status == 404:
|
||||
raise aiohttp.web.HTTPNotFound(text="{} not found on compute".format(url))
|
||||
raise aiohttp.web.HTTPNotFound(text=msg)
|
||||
elif response.status == 409:
|
||||
raise aiohttp.web.HTTPConflict(text="Conflict {} {}".format(url, body))
|
||||
raise aiohttp.web.HTTPConflict(text=msg)
|
||||
elif response.status == 500:
|
||||
raise aiohttp.web.HTTPInternalServerError(text="Internal server error {}".format(url))
|
||||
elif response.status == 503:
|
||||
raise aiohttp.web.HTTPServiceUnavailable(text="Service unavailable {} {}".format(url, body))
|
||||
else:
|
||||
|
@ -25,7 +25,7 @@ import traceback
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
from ..compute.error import NodeError
|
||||
from ..compute.error import NodeError, ImageMissingError
|
||||
from ..controller.controller_error import ControllerError
|
||||
from ..ubridge.ubridge_error import UbridgeError
|
||||
from .response import Response
|
||||
@ -198,10 +198,10 @@ class Route(object):
|
||||
response.set_status(409)
|
||||
response.json({"message": str(e), "status": 409})
|
||||
except (NodeError, UbridgeError, ImageMissingError) as e:
|
||||
log.error("Node error detected: {type}".format(type=type(e)), exc_info=1)
|
||||
log.error("Node error detected: {type}".format(type=e.__class__.__name__), exc_info=1)
|
||||
response = Response(request=request, route=route)
|
||||
response.set_status(409)
|
||||
response.json({"message": str(e), "status": 409, "exception": str(e.__class__)})
|
||||
response.json({"message": str(e), "status": 409, "exception": e.__class__.__name__})
|
||||
except asyncio.futures.CancelledError as e:
|
||||
log.error("Request canceled")
|
||||
response = Response(request=request, route=route)
|
||||
|
Loading…
Reference in New Issue
Block a user