Skip to content

Commit

Permalink
feat(dhis2): support post requests
Browse files Browse the repository at this point in the history
  • Loading branch information
yannforget committed Aug 22, 2023
1 parent 46a508c commit 41c1702
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion openhexa/toolbox/dhis2/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def raise_if_error(response: requests.Response):
if response.status_code != 200 and "json" in response.headers["content-type"]:
msg = response.json()
if msg.get("status") == "ERROR":
raise DHIS2Error(f"{msg.get('status')} {msg.get('httpStatusCode')}:" f" {msg.get('message')}")
raise DHIS2Error(f"{msg.get('status')} {msg.get('httpStatusCode')}: {msg.get('message')}")

# raise with requests if no error message provided
response.raise_for_status()
Expand Down Expand Up @@ -111,3 +111,8 @@ def merge_pages(pages: Sequence[requests.Response]) -> dict:
for page in pages:
merged_response[key] += page.json()[key]
return merged_response

def post(self, endpoint: str, json: dict = None, params: dict = None) -> requests.Response:
r = self.session.post(f"{self.url}/{endpoint}", json=json, params=params)
self.raise_if_error(r)
return r

0 comments on commit 41c1702

Please sign in to comment.