From 96077993fd5b5af5858960289b06a497d4f6f51b Mon Sep 17 00:00:00 2001 From: Nora-Olivia-Ammann <103038637+Nora-Olivia-Ammann@users.noreply.github.com> Date: Tue, 12 Mar 2024 09:54:54 +0100 Subject: [PATCH] fix(create): fix crash when no project is on the server (DEV-3405) (#875) --- src/dsp_tools/commands/project/models/project.py | 10 ++++++---- src/dsp_tools/utils/connection_live.py | 1 + .../commands/project/test_models_project.py | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/dsp_tools/commands/project/models/project.py b/src/dsp_tools/commands/project/models/project.py index dfdaa0d1b..8e27f3996 100644 --- a/src/dsp_tools/commands/project/models/project.py +++ b/src/dsp_tools/commands/project/models/project.py @@ -21,6 +21,7 @@ from dsp_tools.commands.project.models.model import Model from dsp_tools.models.exceptions import BaseError +from dsp_tools.models.exceptions import InputError from dsp_tools.models.langstring import LangString from dsp_tools.utils.connection import Connection @@ -352,7 +353,8 @@ def getAllProjects(con: Connection) -> list[Project]: :param con: Connection instance :return: """ - result = con.get(Project.ROUTE) - if "projects" not in result: - raise BaseError("Request got no projects!") - return [Project.fromJsonObj(con, a) for a in result["projects"]] + try: + result = con.get(Project.ROUTE) + return [Project.fromJsonObj(con, a) for a in result["projects"]] + except InputError: + return [] diff --git a/src/dsp_tools/utils/connection_live.py b/src/dsp_tools/utils/connection_live.py index 3103d2967..bef735f76 100644 --- a/src/dsp_tools/utils/connection_live.py +++ b/src/dsp_tools/utils/connection_live.py @@ -291,6 +291,7 @@ def _handle_non_ok_responses(self, response: Response, request_url: str, retry_c r"OntologyConstraintException", r"DuplicateValueException", r"Project '[0-9A-F]{4}' not found", + r"No projects found", ] if "v2/authentication" in request_url and response.status_code == HTTP_UNAUTHORIZED: raise BadCredentialsError("Bad credentials") diff --git a/test/integration/commands/project/test_models_project.py b/test/integration/commands/project/test_models_project.py index e4946c984..4b71ad0e9 100644 --- a/test/integration/commands/project/test_models_project.py +++ b/test/integration/commands/project/test_models_project.py @@ -35,7 +35,7 @@ def test_return_values(project: Project) -> None: assert project.keywords == set() -def test__toJsonObj_create(project: Project) -> None: +def test_toJsonObj_create(project: Project) -> None: res_json = project._toJsonObj_create() expected = { "shortcode": "0FF0",