Skip to content

Commit a6bbd68

Browse files
committed
Log a repeated validation error reason once
1 parent 64ff68f commit a6bbd68

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎app/errors/handlers.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def summarize_reason(exc: Exception) -> str:
3030
f"{'.'.join(str(loc) for loc in err.get('loc', ()))}: {err.get('msg', '')}".strip(" :")
3131
for err in exc.errors()
3232
]
33-
return "; ".join(r for r in reasons if r) or "validation error"
33+
return "; ".join(dict.fromkeys(r for r in reasons if r)) or "validation error"
3434
return str(exc)
3535

3636

‎tests/routers/test_localization_list.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from app.debug.crypto_service_api_client_mock import CryptoServiceApiClientMock
88
from app.logging.events import Log
99
from app.models.auth.data import AuthorizationScope
10+
from app.models.fhir.resources.data import PSEUDONYM_SYSTEM
1011
from app.models.pseudonym import EncryptedPseudonym
1112
from app.models.ura import UraNumber
1213
from app.services.key_info import KeyInfoService
@@ -235,6 +236,15 @@ def test_keeps_the_subject_token_out_of_an_invalid_localization_log(self, locali
235236
entry = assert_event_emitted(records, Log.INVALID_REQUEST, http_status=422)
236237
assert "leaky-token-value" not in entry.message["error_reason"]
237238

239+
def test_logs_an_invalid_subject_token_reason_once(self, localize_client: TestClient) -> None:
240+
with capture_records() as records:
241+
localize_client.get("/fhir/List", params={"subject:identifier": f"{PSEUDONYM_SYSTEM}|not-a-token"})
242+
243+
entry = assert_event_emitted(records, Log.INVALID_REQUEST, http_status=422)
244+
assert entry.message["error_reason"] == (
245+
"query.subject:identifier: Value error, Invalid pseudonym in subject:identifier"
246+
)
247+
238248
def test_localize_query_requires_localize_scope(self, client: TestClient) -> None:
239249
response = client.get("/fhir/List", params={"subject:identifier": TEST_PSEUDONYM_TOKEN})
240250

0 commit comments

Comments
 (0)