Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): add Accept header to fetch requests for JSON response #1175

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading