Fix error handling in StoreService
This commit is contained in:
parent
f50491a47e
commit
dda7096984
2 changed files with 15 additions and 9 deletions
|
|
@ -23,17 +23,17 @@ class TagsIdResponse(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
class ListComponentResponse(BaseModel):
|
class ListComponentResponse(BaseModel):
|
||||||
id: UUID
|
id: Optional[UUID] = None
|
||||||
name: Optional[str]
|
name: Optional[str] = None
|
||||||
description: Optional[str]
|
description: Optional[str] = None
|
||||||
liked_by_count: Optional[int]
|
liked_by_count: Optional[int] = None
|
||||||
liked_by_user: Optional[bool] = None
|
liked_by_user: Optional[bool] = None
|
||||||
is_component: Optional[bool]
|
is_component: Optional[bool] = None
|
||||||
metadata: Optional[dict]
|
metadata: Optional[dict] = {}
|
||||||
user_created: Optional[dict]
|
user_created: Optional[dict] = {}
|
||||||
tags: Optional[List[TagResponse]] = None
|
tags: Optional[List[TagResponse]] = None
|
||||||
downloads_count: Optional[int]
|
downloads_count: Optional[int] = None
|
||||||
last_tested_version: Optional[str]
|
last_tested_version: Optional[str] = None
|
||||||
private: Optional[bool] = None
|
private: Optional[bool] = None
|
||||||
|
|
||||||
# tags comes as a TagsIdResponse but we want to return a list of TagResponse
|
# tags comes as a TagsIdResponse but we want to return a list of TagResponse
|
||||||
|
|
|
||||||
|
|
@ -343,6 +343,10 @@ class StoreService(Service):
|
||||||
try:
|
try:
|
||||||
errors = response.json()
|
errors = response.json()
|
||||||
message = errors["errors"][0]["message"]
|
message = errors["errors"][0]["message"]
|
||||||
|
if message == "An unexpected error occurred.":
|
||||||
|
# This is a bug in Directus that returns this error
|
||||||
|
# when an error was thrown in the flow
|
||||||
|
message = "You already have a component with this name. Please choose a different name."
|
||||||
raise FilterError(message)
|
raise FilterError(message)
|
||||||
except UnboundLocalError:
|
except UnboundLocalError:
|
||||||
pass
|
pass
|
||||||
|
|
@ -458,6 +462,8 @@ class StoreService(Service):
|
||||||
raise ForbiddenError("You are not authorized to access this public resource")
|
raise ForbiddenError("You are not authorized to access this public resource")
|
||||||
elif exc.response.status_code == 401:
|
elif exc.response.status_code == 401:
|
||||||
raise APIKeyError("You are not authorized to access this resource. Please check your API key.")
|
raise APIKeyError("You are not authorized to access this resource. Please check your API key.")
|
||||||
|
except Exception as exc:
|
||||||
|
raise ValueError(f"Unexpected error: {exc}")
|
||||||
try:
|
try:
|
||||||
if result and not metadata:
|
if result and not metadata:
|
||||||
if len(result) >= limit:
|
if len(result) >= limit:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue