Skip to content

Commit

Permalink
fix(create): fix crash when no project is on the server (DEV-3405) (#875
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Nora-Olivia-Ammann committed Mar 12, 2024
1 parent 1e2e170 commit 9607799
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/dsp_tools/commands/project/models/project.py
Expand Up @@ -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

Expand Down Expand Up @@ -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 []
1 change: 1 addition & 0 deletions src/dsp_tools/utils/connection_live.py
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion test/integration/commands/project/test_models_project.py
Expand Up @@ -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",
Expand Down

0 comments on commit 9607799

Please sign in to comment.