Skip to content

Commit

Permalink
Use 404 status for not running container error
Browse files Browse the repository at this point in the history
  • Loading branch information
romasku committed Apr 12, 2021
1 parent ea365d7 commit 456c20f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 11 additions & 1 deletion platform_monitoring/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
json_response,
middleware,
)
from aiohttp.web_exceptions import HTTPNotFound
from aiohttp_security import check_authorized
from aiohttp_security.api import AUTZ_KEY
from neuro_auth_client import AuthClient, Permission
Expand All @@ -51,7 +52,13 @@
S3Config,
)
from .config_factory import EnvironConfigFactory
from .jobs_service import Container, ExecCreate, JobException, JobsService
from .jobs_service import (
Container,
ExecCreate,
JobException,
JobNotRunningException,
JobsService,
)
from .kube_client import JobError, KubeClient, KubeTelemetry
from .user import untrusted_user
from .utils import (
Expand Down Expand Up @@ -573,6 +580,9 @@ async def handle_exceptions(
except ValueError as e:
payload = {"error": str(e)}
return json_response(payload, status=HTTPBadRequest.status_code)
except JobNotRunningException as e:
payload = {"error": str(e)}
return json_response(payload, status=HTTPNotFound.status_code)
except JobException as e:
payload = {"error": str(e)}
return json_response(payload, status=HTTPBadRequest.status_code)
Expand Down
6 changes: 5 additions & 1 deletion platform_monitoring/jobs_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class JobException(Exception):
pass


class JobNotRunningException(JobException):
pass


class NodeNotFoundException(Exception):
def __init__(self, name: str) -> None:
super().__init__(f"Node {name!r} was not found")
Expand Down Expand Up @@ -131,7 +135,7 @@ async def attach(
while checks > 0:
data = await container.show()
if not data["State"]["Running"]:
raise JobException(f"Job '{job.id}' is not running.")
raise JobNotRunningException(f"Job '{job.id}' is not running.")
checks -= 1
if checks > 0:
await asyncio.sleep(0.5)
Expand Down

0 comments on commit 456c20f

Please sign in to comment.