Skip to content

Commit

Permalink
Merge pull request #2868 from activeloopai/feature/PLAT-441
Browse files Browse the repository at this point in the history
[PLAT-441] Ensure messages are better propagated
  • Loading branch information
dgaloop authored Jun 4, 2024
2 parents 8836e6c + fbf4087 commit 56319fe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 35 deletions.
26 changes: 10 additions & 16 deletions deeplake/client/client.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import os

import deeplake
import requests # type: ignore
import textwrap
from typing import Any, Optional, Dict, List, Union
from typing import Any, Optional, Dict
from deeplake.util.exceptions import (
AgreementNotAcceptedError,
AuthorizationException,
LoginException,
InvalidPasswordException,
ManagedCredentialsNotFoundError,
NotLoggedInAgreementError,
ResourceNotFoundException,
InvalidTokenException,
UserNotLoggedInException,
TokenPermissionError,
)
from deeplake.client.utils import (
Expand Down Expand Up @@ -125,11 +119,6 @@ def request(
headers["hub-cli-version"] = self.version
headers = {**headers, **self.auth_context.get_auth_headers()}

# clearer error than `ServerUnderMaintenence`
if json is not None and "password" in json and json["password"] is None:
# do NOT pass in the password here. `None` is explicitly typed.
raise InvalidPasswordException("Password cannot be `None`.")

status_code = None
tries = 0
while status_code is None or (status_code in retry_status_codes and tries < 3):
Expand Down Expand Up @@ -205,8 +194,11 @@ def get_dataset_credentials(
).json()
except Exception as e:
if isinstance(e, AuthorizationException):
response_data = e.response.json()
code = response_data.get("code")
code = -1
if e.response is not None:
response_data = e.response.json()
code = response_data.get("code")

if code == 1:
agreements = response_data["agreements"]
agreements = [agreement["text"] for agreement in agreements]
Expand All @@ -215,11 +207,13 @@ def get_dataset_credentials(
raise NotLoggedInAgreementError from e
else:
try:
jwt.decode(self.token, options={"verify_signature": False})
jwt.decode(
self.get_token(), options={"verify_signature": False}
)
except Exception:
raise InvalidTokenException

raise TokenPermissionError()
raise TokenPermissionError(e.original_message)
raise
full_url = response.get("path")
repository = response.get("repository")
Expand Down
25 changes: 6 additions & 19 deletions deeplake/util/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import requests
import numpy as np
import deeplake
from typing import Any, List, Sequence, Tuple, Optional, Union

import deeplake


class ExternalCommandError(Exception):
def __init__(self, command: str, status: int):
Expand Down Expand Up @@ -189,14 +191,6 @@ def __init__(self, message):
super().__init__(message)


class LoginException(Exception):
def __init__(
self,
message="Error while logging in, invalid auth token. Please try logging in again.",
):
super().__init__(message)


class UserNotLoggedInException(Exception):
def __init__(self):
message = (
Expand Down Expand Up @@ -237,21 +231,14 @@ def __init__(self, message="Authentication failed. Please try logging in again."
class AuthorizationException(Exception):
def __init__(
self,
message="You are not authorized to access this resource on Activeloop Server.",
response=None,
message: Optional[str] = None,
response: Optional[requests.Response] = None,
):
self.original_message = message
self.response = response
super().__init__(message)


class InvalidPasswordException(AuthorizationException):
def __init__(
self,
message="The password you provided was invalid.",
):
super().__init__(message)


class CouldNotCreateNewDatasetException(AuthorizationException):
def __init__(
self,
Expand Down

0 comments on commit 56319fe

Please sign in to comment.