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

Raise exceptions in core #83

Open
ricardogsilva opened this issue Jan 3, 2025 · 0 comments
Open

Raise exceptions in core #83

ricardogsilva opened this issue Jan 3, 2025 · 0 comments
Assignees
Milestone

Comments

@ricardogsilva
Copy link
Collaborator

Python's error handling is usually done by raising exceptions and catching them in client code.

As such, let's follow this pattern in core. Whenever a function errors out, instead of returning normally with an error object, let's raise an exception and pass the responsibility of handling it up to the caller.

In practice, this means that while working with functions like

def get_workspace(self, workspace: str) -> Union[WorkspaceModel, GSResponse]:
        client = self.http_client
        response = client.get(f"workspaces/{workspace}")
        if response.status_code == 200:
            return WorkspaceModel.model_validate(response.json())
        else:
            return self.response_recognise(response.status_code)

Instead of returning the error with whatever object is generated by self.response_recognize() (which is nicely presented), we'd raise an exception.

check if we can give back error message that httpx gives

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

2 participants