Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor error handling for scope cloning #1458

Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions pykechain/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2358,7 +2358,9 @@ def clone_scope(
query_params = API_EXTRA_PARAMS["scopes"]
response = self._request("POST", url, params=query_params, json=data_dict)

if response.status_code != requests.codes.created: # pragma: no cover
try:
response.raise_for_status()
except requests.exceptions.HTTPError as err:
if response.status_code == requests.codes.forbidden:
raise ForbiddenError(
f"Forbidden to clone Scope {source_scope}", response=response
Expand All @@ -2368,16 +2370,21 @@ def clone_scope(
f"Could not clone Scope {source_scope}", response=response
)

if asynchronous:
if asynchronous and response.status_code == requests.codes.accepted:
return None
elif response.status_code == requests.codes.created:

cloned_scope = Scope(response.json()["results"][0], client=source_scope._client)
cloned_scope = Scope(response.json()["results"][0], client=source_scope._client)

# TODO work-around, some attributes are not (yet) in the KE-chain response.json()
cloned_scope._tags = tags
cloned_scope.start_date = start_date
cloned_scope.due_date = due_date
return cloned_scope
# TODO work-around, some attributes are not (yet) in the KE-chain response.json()
cloned_scope._tags = tags
cloned_scope.start_date = start_date
cloned_scope.due_date = due_date
return cloned_scope
else:
raise APIError(
f"Unexpected response. Could not clone Scope {source_scope}", response=response
)

def create_team(
self,
Expand Down