Skip to content

Commit 1679090

Browse files
authored
Merge pull request #25 from ardevd/move-http-exception
refactor: moved HTTPError into errors.py
2 parents 875b4ea + 8536fd7 commit 1679090

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

dimo/dimo.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from typing_extensions import Optional
21
from requests import Session
32

43
from .api.attestation import Attestation
@@ -21,7 +20,9 @@
2120

2221
class DIMO:
2322

24-
def __init__(self, env: str = "Production", session: Optional[Session] = None) -> None:
23+
def __init__(
24+
self, env: str = "Production", session: Optional[Session] = None
25+
) -> None:
2526

2627
self.env = env
2728
# Assert valid environment specified
@@ -32,7 +33,9 @@ def __init__(self, env: str = "Production", session: Optional[Session] = None) -
3233

3334
self._client_id: Optional[str] = None
3435
self._services: Dict[str, Any] = {}
35-
self.session = session or Session() # Use the provided session or create a new one
36+
self.session = (
37+
session or Session()
38+
) # Use the provided session or create a new one
3639

3740
# Creates a full path for endpoints combining DIMO service, specific endpoint, and optional params
3841
def _get_full_path(self, service: str, path: str, params=None) -> str:

dimo/errors.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,12 @@ def check_optional_type(param_name: str, value: Any, expected_type: Union[Type,
3030

3131
class DimoValueError(DimoError):
3232
pass
33+
34+
35+
class HTTPError(Exception):
36+
"""Http error wrapper with status code and (optional) response body"""
37+
38+
def __init__(self, status: int, message: str, body: Any = None):
39+
super().__init__(f"HTTP {status}: {message}")
40+
self.status = status
41+
self.body = body

dimo/request.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
import json
2-
from typing import Any
32
from requests import Session, RequestException
4-
5-
6-
class HTTPError(Exception):
7-
"""Http error wrapper with status code and (optional) response body"""
8-
9-
def __init__(self, status: int, message: str, body: Any = None):
10-
super().__init__(f"HTTP {status}: {message}")
11-
self.status = status
12-
self.body = body
3+
from .errors import HTTPError
134

145

156
class Request:

tests/test_request.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
from requests import RequestException
44
from unittest.mock import Mock
55

6-
from dimo.request import Request, HTTPError
6+
from dimo.errors import HTTPError
7+
from dimo.request import Request
78

89

910
class DummyResponse:

0 commit comments

Comments
 (0)