🐛 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:
parent
d11b199ca4
commit
acc6cd6e4e
1 changed files with 7 additions and 2 deletions
|
|
@ -199,8 +199,13 @@ class StoreService(Service):
|
||||||
self.components_url, headers=headers, json=component_dict
|
self.components_url, headers=headers, json=component_dict
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
# ! If the user does not have permission to a certain field
|
||||||
|
# the request returns 204 and no data
|
||||||
|
try:
|
||||||
component = response.json()["data"]
|
component = response.json()["data"]
|
||||||
return ComponentResponse(**component)
|
return ComponentResponse(**component)
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
return ComponentResponse(**component_dict)
|
||||||
except HTTPError as exc:
|
except HTTPError as exc:
|
||||||
if response:
|
if response:
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue