Skip to content

Commit f93fbac

Browse files
authored
Print out resolution when it exists (#98)
1 parent d8cf556 commit f93fbac

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

src/ansys/simai/core/utils/requests.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,11 @@ def handle_http_errors(response: requests.Response) -> None:
6969
if response.status_code == 404:
7070
raise NotFoundError(f"{message}", response) from e
7171
else:
72+
error_message = f"{response.status_code} {message}"
73+
if resolution := json_response.get("resolution", ""):
74+
error_message += f"\n{resolution}"
7275
raise ApiClientError(
73-
f"{response.status_code} {message}",
76+
error_message,
7477
response,
7578
) from e
7679
else:

tests/test_models.py

+65-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
ModelOutput,
3636
PostProcessInput,
3737
)
38-
from ansys.simai.core.errors import InvalidArguments, ProcessingError
38+
from ansys.simai.core.errors import ApiClientError, InvalidArguments, ProcessingError
3939

4040
if TYPE_CHECKING:
4141
from ansys.simai.core.data.models import Model
@@ -584,3 +584,67 @@ def test_post_process_input(simai_client):
584584
build_model.fields["configuration"]["fields"]["surface_pp_input"]
585585
== model_conf_dict["fields"]["surface_pp_input"]
586586
)
587+
588+
589+
@responses.activate
590+
def test_failed_build_with_resolution(simai_client):
591+
"""WHEN I call launch_build() with using a new build configuration
592+
THEN I get a Model object, its project_id matches the
593+
id of the project, and its configuration is a
594+
ModelConfiguration and its content matches the raw conf.
595+
"""
596+
597+
raw_project = {
598+
"id": MODEL_RAW["project_id"],
599+
"name": "fifi",
600+
"sample": SAMPLE_RAW,
601+
}
602+
603+
responses.add(
604+
responses.GET,
605+
f"https://test.test/projects/{MODEL_RAW['project_id']}",
606+
json=raw_project,
607+
status=200,
608+
)
609+
610+
project: Project = simai_client._project_directory._model_from(raw_project)
611+
612+
lgth = ("relative_to_max", 5, 8.1)
613+
wdth = ("relative_to_max", 5, 8.1)
614+
hght = ("absolute", -4.5, 0.1)
615+
616+
doa = DomainOfAnalysis(
617+
length=lgth,
618+
width=wdth,
619+
height=hght,
620+
)
621+
622+
new_conf = ModelConfiguration(
623+
project=project,
624+
build_preset="debug",
625+
domain_of_analysis=doa,
626+
)
627+
response_json = {
628+
"status": "Conflict",
629+
"errors": {
630+
"fields_discrepancies": [
631+
{
632+
"id": "2a324",
633+
"name": "td-987",
634+
"message": "Missing fields: p (volume), p_rgh (volume)",
635+
}
636+
]
637+
},
638+
"resolution": "This is a resolution.",
639+
}
640+
641+
responses.add(
642+
responses.POST,
643+
f"https://test.test/projects/{MODEL_RAW['project_id']}/model",
644+
json=response_json,
645+
status=409,
646+
)
647+
648+
with pytest.raises(ApiClientError) as e:
649+
simai_client.models.build(new_conf)
650+
assert "This is a resolution." in str(e.value)

0 commit comments

Comments
 (0)