Skip to content
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
9 changes: 6 additions & 3 deletions dimo/dimo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from typing_extensions import Optional
from requests import Session

from .api.attestation import Attestation
Expand All @@ -21,7 +20,9 @@

class DIMO:

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

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

self._client_id: Optional[str] = None
self._services: Dict[str, Any] = {}
self.session = session or Session() # Use the provided session or create a new one
self.session = (
session or Session()
) # Use the provided session or create a new one

# Creates a full path for endpoints combining DIMO service, specific endpoint, and optional params
def _get_full_path(self, service: str, path: str, params=None) -> str:
Expand Down
9 changes: 9 additions & 0 deletions dimo/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,12 @@ def check_optional_type(param_name: str, value: Any, expected_type: Union[Type,

class DimoValueError(DimoError):
pass


class HTTPError(Exception):
"""Http error wrapper with status code and (optional) response body"""

def __init__(self, status: int, message: str, body: Any = None):
super().__init__(f"HTTP {status}: {message}")
self.status = status
self.body = body
11 changes: 1 addition & 10 deletions dimo/request.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import json
from typing import Any
from requests import Session, RequestException


class HTTPError(Exception):
"""Http error wrapper with status code and (optional) response body"""

def __init__(self, status: int, message: str, body: Any = None):
super().__init__(f"HTTP {status}: {message}")
self.status = status
self.body = body
from .errors import HTTPError


class Request:
Expand Down
3 changes: 2 additions & 1 deletion tests/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from requests import RequestException
from unittest.mock import Mock

from dimo.request import Request, HTTPError
from dimo.errors import HTTPError
from dimo.request import Request


class DummyResponse:
Expand Down