Skip to content

Commit

Permalink
Move SeamInvalidTokenError to seam/exceptions.py
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-balitskyi committed Aug 1, 2024
1 parent a3733fb commit 6e936d2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 22 deletions.
2 changes: 1 addition & 1 deletion seam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
from .seam import Seam
from .seam_multi_workspace import SeamMultiWorkspace
from .options import SeamInvalidOptionsError
from .auth import SeamInvalidTokenError
from .exceptions import (
SeamHttpApiError,
SeamHttpUnauthorizedError,
SeamHttpInvalidInputError,
SeamActionAttemptError,
SeamActionAttemptFailedError,
SeamActionAttemptTimeoutError,
SeamInvalidTokenError,
)
from .seam_webhook import SeamWebhook
from svix.webhooks import WebhookVerificationError as SeamWebhookVerificationError
21 changes: 2 additions & 19 deletions seam/auth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from typing import Optional

from .exceptions import SeamInvalidTokenError
from .options import (
SeamInvalidOptionsError,
is_seam_options_with_api_key,
Expand All @@ -15,25 +17,6 @@
)


class SeamInvalidTokenError(Exception):
"""
Exception raised when an invalid token is provided to the Seam client.
This error occurs when a token of incorrect type or format is used for
authentication. It can be raised in various scenarios, such as using a
client session token as an API key, or providing a token with an incorrect
prefix.
"""

def __init__(self, message):
"""
:param message: Detailed description of the invalid token
:type message: str
"""

super().__init__(f"Seam received an invalid token: {message}")


def get_auth_headers(
api_key: Optional[str] = None,
personal_access_token: Optional[str] = None,
Expand Down
20 changes: 20 additions & 0 deletions seam/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,23 @@ def __init__(self, action_attempt: ActionAttempt, timeout: str):
message = f"Timed out waiting for action attempt after {timeout}s"
super().__init__(message, action_attempt)
self.name = self.__class__.__name__


# Auth
class SeamInvalidTokenError(Exception):
"""
Exception raised when an invalid token is provided to the Seam client.
This error occurs when a token of incorrect type or format is used for
authentication. It can be raised in various scenarios, such as using a
client session token as an API key, or providing a token with an incorrect
prefix.
"""

def __init__(self, message):
"""
:param message: Detailed description of the invalid token
:type message: str
"""

super().__init__(f"Seam received an invalid token: {message}")
2 changes: 1 addition & 1 deletion test/api_key_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from seam import Seam
from seam.auth import SeamInvalidTokenError
from seam.exceptions import SeamInvalidTokenError


def test_seam_client_from_api_key_returns_instance_authorized_with_api_key(
Expand Down
2 changes: 1 addition & 1 deletion test/personal_access_token_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from seam import Seam
from seam.auth import SeamInvalidTokenError
from seam.exceptions import SeamInvalidTokenError
from seam.seam_multi_workspace import SeamMultiWorkspace


Expand Down

0 comments on commit 6e936d2

Please sign in to comment.