🐛 fix(service.py): handle JSONDecodeError when response does not contain data field to prevent server error

 feat(service.py): return ComponentResponse with component_dict when response does not contain data field to provide consistent response format
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-10-26 11:31:35 -03:00
commit acc6cd6e4e

View file

@ -199,8 +199,13 @@ class StoreService(Service):
self.components_url, headers=headers, json=component_dict
)
response.raise_for_status()
component = response.json()["data"]
return ComponentResponse(**component)
# ! If the user does not have permission to a certain field
# the request returns 204 and no data
try:
component = response.json()["data"]
return ComponentResponse(**component)
except json.JSONDecodeError:
return ComponentResponse(**component_dict)
except HTTPError as exc:
if response:
try: