Skip to content

Commit

Permalink
Minor improvements and bug fixes (#66)
Browse files Browse the repository at this point in the history
## changes

- [x] pretty printing of errors for not found resources
- [x] fixed a bug in printing of rows in the CLI
  • Loading branch information
sg-s authored Aug 7, 2024
1 parent 34a85eb commit 2eea193
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/data_hub/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
import sys

from deeporigin import auth
from deeporigin.exceptions import DeepOriginException
from deeporigin.utils import _get_method, _print_dict
from deeporigin_data import AuthenticationError, DeeporiginData
from deeporigin_data import AuthenticationError, DeeporiginData, NotFoundError

# this list specifies methods in the low level API that should
# not be automatically wrapped
Expand Down Expand Up @@ -123,6 +124,13 @@ def dynamic_function(
response = method(**kwargs)
else:
raise error
except NotFoundError as error:
message = error.body["errors"][0]["title"]
raise DeepOriginException(
message,
fix="Could not find resource. Please check ID and organization to make sure this resource exists. ",
title="Deep Origin Error: [Resource Not Found]",
)

if debug:
print(f"Response request = {response.http_request}")
Expand Down
6 changes: 5 additions & 1 deletion src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ def _truncate(txt: str) -> str:
"""Utility function for truncating text"""

TERMINAL_WIDTH = int(shutil.get_terminal_size().columns / 2)

if txt is None:
return txt
txt = str(txt)
if len(txt) > TERMINAL_WIDTH:
txt = txt[: TERMINAL_WIDTH - 3] + "..."
return txt
Expand Down Expand Up @@ -106,7 +110,7 @@ def _print_dict(
else:
# truncate values so that long strings
# don't break the table
data = {key: _truncate(str(value)) for key, value in data.items()}
data = {key: _truncate(value) for key, value in data.items()}

if transpose:
data = data.items()
Expand Down

0 comments on commit 2eea193

Please sign in to comment.