🐛 fix(service.py): handle case when response is None to prevent UnboundLocalError
🐛 fix(service.py): handle case when response is None to prevent UnboundLocalError and raise ValueError with error message from response if available
This commit is contained in:
parent
55e28bdeba
commit
b33878088e
1 changed files with 8 additions and 0 deletions
|
|
@ -122,6 +122,7 @@ class StoreService(Service):
|
||||||
headers = {"Authorization": f"Bearer {api_key}"}
|
headers = {"Authorization": f"Bearer {api_key}"}
|
||||||
component_dict = component_data.dict(exclude_unset=True)
|
component_dict = component_data.dict(exclude_unset=True)
|
||||||
# Parent is a UUID, but the store expects a string
|
# Parent is a UUID, but the store expects a string
|
||||||
|
response = None
|
||||||
if component_dict.get("parent"):
|
if component_dict.get("parent"):
|
||||||
component_dict["parent"] = str(component_dict["parent"])
|
component_dict["parent"] = str(component_dict["parent"])
|
||||||
try:
|
try:
|
||||||
|
|
@ -132,4 +133,11 @@ class StoreService(Service):
|
||||||
component = response.json()["data"]
|
component = response.json()["data"]
|
||||||
return ComponentResponse(**component)
|
return ComponentResponse(**component)
|
||||||
except HTTPError as exc:
|
except HTTPError as exc:
|
||||||
|
if response:
|
||||||
|
try:
|
||||||
|
errors = response.json()
|
||||||
|
message = errors["errors"][0]["message"]
|
||||||
|
raise ValueError(message)
|
||||||
|
except UnboundLocalError:
|
||||||
|
pass
|
||||||
raise ValueError(f"Upload failed: {exc}")
|
raise ValueError(f"Upload failed: {exc}")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue