Skip to content

Make Exceptions proper objects with members #32

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

Merged
merged 1 commit into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 8 additions & 2 deletions src/openqa_client/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

"""Custom exceptions used by openqa_client."""

from requests.exceptions import ConnectionError as RConnectionError


class OpenQAClientError(Exception):
"""Base class for openQA client errors."""
Expand All @@ -29,12 +31,16 @@ class ConnectionError(OpenQAClientError):
requests.exceptions.ConnectionError.
"""

pass
def __init__(self, err: RConnectionError) -> None:
self.err = err


class RequestError(OpenQAClientError):
"""Error raised when a request fails (after retries). 3-tuple of
method, URL, and status code.
"""

pass
def __init__(self, method: str, url: str, status_code: int) -> None:
self.method = method
self.url = url
self.status_code = status_code
14 changes: 14 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,17 @@ def test_get_jobs(self, fakerequest, fakeclones, simple_config):
assert fakerequest.call_args[0][2] == "jobs"
assert fakerequest.call_args[1]["params"] == {"build": "foo"}
assert fakeclones.call_count == 1

def test_client_errors(self):
"""Test creation of exceptions"""
err = oqe.RequestError("GET", "http://localhost", 404)
assert err.args[0] == "GET"
assert err.args[1] == "http://localhost"
assert err.args[2] == 404
assert err.method == "GET"
assert err.url == "http://localhost"
assert err.status_code == 404

err = oqe.ConnectionError("oh no")
assert err.args[0] == "oh no"
assert err.err == "oh no"