Skip to content

Commit 8170eb1

Browse files
committed
Removing unnecessary try/except blocks
1 parent fb86524 commit 8170eb1

2 files changed

Lines changed: 29 additions & 31 deletions

File tree

qfieldcloud_sdk/cli.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -468,19 +468,12 @@ def delta_push(ctx: Context, project_id: str, delta_filename: str) -> None:
468468
"""Push a delta file to a project with PROJECT_ID."""
469469
log(f'Pushing delta file "{delta_filename}" to project "{project_id}"…')
470470

471-
try:
472-
response = ctx.obj["client"].push_delta(project_id, delta_filename)
471+
response = ctx.obj["client"].push_delta(project_id, delta_filename)
473472

474-
if ctx.obj["format_json"]:
475-
print_json(response)
476-
else:
477-
log(f'Delta file "{delta_filename}" pushed to project "{project_id}".')
478-
except Exception as e:
479-
log(f"Error pushing delta file: {e}")
480-
if ctx.obj["format_json"]:
481-
print_json({"error": str(e)})
482-
else:
483-
click.echo(f"Error: {e}", err=True)
473+
if ctx.obj["format_json"]:
474+
print_json(response)
475+
else:
476+
log(f'Delta file "{delta_filename}" pushed to project "{project_id}".')
484477

485478

486479
@cli.command()

qfieldcloud_sdk/sdk.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,20 @@ def is_empty(self) -> bool:
183183
return self.limit is None and self.offset is None
184184

185185

186+
class DeltaPushResponse(TypedDict):
187+
"""Represents the structure of the response for pushing a delta file.
188+
189+
Attributes:
190+
status: The status of the response.
191+
message: A message providing additional information about the response.
192+
details: Additional details about the delta push operation.
193+
"""
194+
195+
status: str
196+
message: Optional[str]
197+
details: Optional[Dict[str, Any]]
198+
199+
186200
class Client:
187201
"""The core component of the QFieldCloud SDK, providing methods for interacting with the QFieldCloud platform.
188202
@@ -617,34 +631,25 @@ def job_status(self, job_id: str) -> Dict[str, Any]:
617631

618632
return resp.json()
619633

620-
def push_delta(self, project_id: str, delta_filename: str) -> Dict[str, Any]:
634+
def push_delta(self, project_id: str, delta_filename: str) -> DeltaPushResponse:
621635
"""Push a delta file to a project.
622636
623637
Args:
624638
project_id: Project ID.
625639
delta_filename: Path to the delta JSON file.
626640
627641
Returns:
628-
A dictionary containing the response from the server.
642+
A DeltaPushResponse containing the response from the server.
629643
"""
630-
try:
631-
with open(delta_filename, "r") as delta_file:
632-
files = {"file": delta_file}
633-
resp = self._request(
634-
"POST",
635-
f"deltas/{project_id}/",
636-
files={
637-
"file": delta_file
638-
},
639-
)
640-
print(f"Response status code: {resp.status_code}")
644+
with open(delta_filename, "r") as delta_file:
645+
files = {"file": delta_file}
646+
response = self._request(
647+
"POST",
648+
f"deltas/{project_id}/",
649+
files=files,
650+
)
641651

642-
if resp.content:
643-
return resp.json()
644-
else:
645-
return {"message": "Delta pushed successfully"}
646-
except Exception as e:
647-
raise RuntimeError(f"Failed to push delta: {e}")
652+
return cast(DeltaPushResponse, response)
648653

649654
def delete_files(
650655
self,

0 commit comments

Comments
 (0)