Skip to content

Commit

Permalink
Merge pull request #1175 from betagouv/fix/opentheso-add-accept-header
Browse files Browse the repository at this point in the history
fix(api): add Accept header to fetch requests for JSON response
  • Loading branch information
wiwski authored Dec 9, 2024
2 parents c031f2c + 898959c commit d9036d7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion euphrosyne/assets/js/web-components/open-theso-type-ahead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export abstract class OpenThesoTypeAhead extends TypeAheadList {
// autocomplete
url = `https://opentheso.huma-num.fr/opentheso/openapi/v1/concept/${this.thesorusId}/autocomplete/${q}?lang=fr&exactMatch=false`;
}
const response = await fetch(url);
const response = await fetch(url, {
headers: { Accept: "application/json" },
});

if (response && response.status === 404) {
return [];
Expand Down
3 changes: 2 additions & 1 deletion lab/tests/test_opentheso.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def test_fetch_parent_ids_from_id(request_mock: mock.MagicMock):
assert fetch_parent_ids_from_id("theso_id", "concept_id") == ["FIRST", "SECOND"]
request_mock.get.assert_called_once_with(
# pylint: disable=line-too-long
"https://opentheso.huma-num.fr/opentheso/openapi/v1/concept/theso_id/concept_id/expansion?way=top",
"https://opentheso.huma-num.fr/openapi/v1/concept/theso_id/concept_id/expansion?way=top",
headers={"Accept": "application/json"},
timeout=5,
)
3 changes: 2 additions & 1 deletion lab/thesauri/opentheso.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def fetch_parent_ids_from_id(theso_id: str, concept_id: str) -> list[str]:
try:
response = requests.get(
# pylint: disable=line-too-long
f"https://opentheso.huma-num.fr/opentheso/openapi/v1/concept/{theso_id}/{concept_id}/expansion?way=top",
f"https://opentheso.huma-num.fr/openapi/v1/concept/{theso_id}/{concept_id}/expansion?way=top",
headers={"Accept": "application/json"},
timeout=5,
)
except requests.exceptions.RequestException as e:
Expand Down

0 comments on commit d9036d7

Please sign in to comment.