Skip to content

Commit

Permalink
fix: change ApiError by APIError
Browse files Browse the repository at this point in the history
  • Loading branch information
leynier committed Nov 1, 2021
1 parent eb86078 commit 98e27af
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 40 deletions.
16 changes: 8 additions & 8 deletions gotrue/_async/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from ..constants import COOKIE_OPTIONS, DEFAULT_HEADERS, GOTRUE_URL, STORAGE_KEY
from ..types import (
ApiError,
APIError,
AuthChangeEvent,
CookieOptions,
Provider,
Expand Down Expand Up @@ -403,19 +403,19 @@ async def get_session_from_url(
refresh_token = query.get("refresh_token")
token_type = query.get("token_type")
if error_description:
raise ApiError(error_description[0], 400)
raise APIError(error_description[0], 400)
if not access_token:
raise ApiError("No access_token detected.", 400)
raise APIError("No access_token detected.", 400)
if not expires_in or expires_in[0]:
raise ApiError("No expires_in detected.", 400)
raise APIError("No expires_in detected.", 400)
if not refresh_token:
raise ApiError("No refresh_token detected.", 400)
raise APIError("No refresh_token detected.", 400)
if not token_type:
raise ApiError("No token_type detected.", 400)
raise APIError("No token_type detected.", 400)
try:
expires_at = round(time.time()) + int(expires_in[0])
except ValueError:
raise ApiError("Invalid expires_in.", 400)
raise APIError("Invalid expires_in.", 400)
response = await self.api.get_user(jwt=access_token[0])
provider_token = query.get("provider_token")
session = Session(
Expand Down Expand Up @@ -562,7 +562,7 @@ async def _recover_and_refresh(self) -> None:
await self._call_refresh_token(
refresh_token=session.refresh_token
)
except ApiError:
except APIError:
await self._remove_session()
else:
await self._remove_session()
Expand Down
16 changes: 8 additions & 8 deletions gotrue/_sync/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from ..constants import COOKIE_OPTIONS, DEFAULT_HEADERS, GOTRUE_URL, STORAGE_KEY
from ..types import (
ApiError,
APIError,
AuthChangeEvent,
CookieOptions,
Provider,
Expand Down Expand Up @@ -401,19 +401,19 @@ def get_session_from_url(self, *, url: str, store_session: bool = False) -> Sess
refresh_token = query.get("refresh_token")
token_type = query.get("token_type")
if error_description:
raise ApiError(error_description[0], 400)
raise APIError(error_description[0], 400)
if not access_token:
raise ApiError("No access_token detected.", 400)
raise APIError("No access_token detected.", 400)
if not expires_in or expires_in[0]:
raise ApiError("No expires_in detected.", 400)
raise APIError("No expires_in detected.", 400)
if not refresh_token:
raise ApiError("No refresh_token detected.", 400)
raise APIError("No refresh_token detected.", 400)
if not token_type:
raise ApiError("No token_type detected.", 400)
raise APIError("No token_type detected.", 400)
try:
expires_at = round(time.time()) + int(expires_in[0])
except ValueError:
raise ApiError("Invalid expires_in.", 400)
raise APIError("Invalid expires_in.", 400)
response = self.api.get_user(jwt=access_token[0])
provider_token = query.get("provider_token")
session = Session(
Expand Down Expand Up @@ -558,7 +558,7 @@ def _recover_and_refresh(self) -> None:
if self.auto_refresh_token and session.refresh_token:
try:
self._call_refresh_token(refresh_token=session.refresh_token)
except ApiError:
except APIError:
self._remove_session()
else:
self._remove_session()
Expand Down
4 changes: 2 additions & 2 deletions gotrue/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from httpx import HTTPError, Response

from .types import ApiError, Session, User
from .types import APIError, Session, User

T = TypeVar("T")

Expand All @@ -19,7 +19,7 @@ def parse_response(response: Response, func: Callable[[Any], T]) -> T:
return func(json)
except HTTPError:
json = response.json()
raise ApiError.from_dict(json)
raise APIError.from_dict(json)


def parse_session_or_user(arg: Any) -> Union[Session, User]:
Expand Down
8 changes: 4 additions & 4 deletions gotrue/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def parse_dict(cls: Type[T], **json: dict) -> T:


@dataclass
class ApiError(BaseException):
class APIError(BaseException):
msg: str
code: int

Expand All @@ -38,9 +38,9 @@ def __post_init__(self) -> None:
self.code = int(str(self.code))

@classmethod
def from_dict(cls, data: dict) -> "ApiError":
def from_dict(cls, data: dict) -> "APIError":
if "msg" in data and "code" in data:
return ApiError(
return APIError(
msg=data["msg"],
code=data["code"],
)
Expand All @@ -49,7 +49,7 @@ def from_dict(cls, data: dict) -> "ApiError":
code = int(data["error"])
except ValueError:
code = -1
return ApiError(
return APIError(
msg=data["error_description"],
code=code,
)
Expand Down
10 changes: 5 additions & 5 deletions tests/_async/test_client_with_auto_confirm_disabled.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from faker import Faker

from gotrue import AsyncGoTrueClient
from gotrue.types import ApiError, User
from gotrue.types import APIError, User

GOTRUE_URL = "http://localhost:9999"
TEST_TWILIO = False
Expand Down Expand Up @@ -55,7 +55,7 @@ async def test_sign_up_with_the_same_user_twice_should_throw_an_error(
password=password,
)
assert False
except ApiError as e:
except APIError as e:
assert expected_error_message in e.msg
except Exception as e:
assert False, str(e)
Expand All @@ -71,7 +71,7 @@ async def test_sign_in(client: AsyncGoTrueClient):
password=password,
)
assert False
except ApiError as e:
except APIError as e:
assert e.msg == expected_error_message
except Exception as e:
assert False, str(e)
Expand All @@ -87,7 +87,7 @@ async def test_sign_in_with_the_wrong_password(client: AsyncGoTrueClient):
password=password + "2",
)
assert False
except ApiError as e:
except APIError as e:
assert e.msg == expected_error_message
except Exception as e:
assert False, str(e)
Expand Down Expand Up @@ -119,7 +119,7 @@ async def test_verify_mobile_otp_errors_on_bad_token(client: AsyncGoTrueClient):
try:
await client.verify_otp(phone=phone, token="123456")
assert False
except ApiError as e:
except APIError as e:
assert expected_error_message in e.msg
except Exception as e:
assert False, str(e)
4 changes: 2 additions & 2 deletions tests/_async/test_client_with_auto_confirm_enabled.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from faker import Faker

from gotrue import AsyncGoTrueClient
from gotrue.types import ApiError, Session, User, UserAttributes
from gotrue.types import APIError, Session, User, UserAttributes

GOTRUE_URL = "http://localhost:9998"
TEST_TWILIO = False
Expand Down Expand Up @@ -265,7 +265,7 @@ async def test_sign_in_with_the_wrong_password(client: AsyncGoTrueClient):
try:
await client.sign_in(email=email, password=password + "2")
assert False
except ApiError:
except APIError:
assert True
except Exception as e:
assert False, str(e)
4 changes: 2 additions & 2 deletions tests/_async/test_client_with_sign_ups_disabled.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from faker import Faker

from gotrue import AsyncGoTrueClient
from gotrue.types import ApiError
from gotrue.types import APIError

GOTRUE_URL = "http://localhost:9997"

Expand All @@ -31,7 +31,7 @@ async def test_sign_up(client: AsyncGoTrueClient):
try:
await client.sign_up(email=email, password=password)
assert False
except ApiError as e:
except APIError as e:
assert e.msg == expected_error_message
except Exception as e:
assert False, str(e)
10 changes: 5 additions & 5 deletions tests/_sync/test_client_with_auto_confirm_disabled.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from faker import Faker

from gotrue import SyncGoTrueClient
from gotrue.types import ApiError, User
from gotrue.types import APIError, User

GOTRUE_URL = "http://localhost:9999"
TEST_TWILIO = False
Expand Down Expand Up @@ -55,7 +55,7 @@ def test_sign_up_with_the_same_user_twice_should_throw_an_error(
password=password,
)
assert False
except ApiError as e:
except APIError as e:
assert expected_error_message in e.msg
except Exception as e:
assert False, str(e)
Expand All @@ -71,7 +71,7 @@ def test_sign_in(client: SyncGoTrueClient):
password=password,
)
assert False
except ApiError as e:
except APIError as e:
assert e.msg == expected_error_message
except Exception as e:
assert False, str(e)
Expand All @@ -87,7 +87,7 @@ def test_sign_in_with_the_wrong_password(client: SyncGoTrueClient):
password=password + "2",
)
assert False
except ApiError as e:
except APIError as e:
assert e.msg == expected_error_message
except Exception as e:
assert False, str(e)
Expand Down Expand Up @@ -119,7 +119,7 @@ def test_verify_mobile_otp_errors_on_bad_token(client: SyncGoTrueClient):
try:
client.verify_otp(phone=phone, token="123456")
assert False
except ApiError as e:
except APIError as e:
assert expected_error_message in e.msg
except Exception as e:
assert False, str(e)
4 changes: 2 additions & 2 deletions tests/_sync/test_client_with_auto_confirm_enabled.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from faker import Faker

from gotrue import SyncGoTrueClient
from gotrue.types import ApiError, Session, User, UserAttributes
from gotrue.types import APIError, Session, User, UserAttributes

GOTRUE_URL = "http://localhost:9998"
TEST_TWILIO = False
Expand Down Expand Up @@ -259,7 +259,7 @@ def test_sign_in_with_the_wrong_password(client: SyncGoTrueClient):
try:
client.sign_in(email=email, password=password + "2")
assert False
except ApiError:
except APIError:
assert True
except Exception as e:
assert False, str(e)
4 changes: 2 additions & 2 deletions tests/_sync/test_client_with_sign_ups_disabled.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from faker import Faker

from gotrue import SyncGoTrueClient
from gotrue.types import ApiError
from gotrue.types import APIError

GOTRUE_URL = "http://localhost:9997"

Expand All @@ -31,7 +31,7 @@ def test_sign_up(client: SyncGoTrueClient):
try:
client.sign_up(email=email, password=password)
assert False
except ApiError as e:
except APIError as e:
assert e.msg == expected_error_message
except Exception as e:
assert False, str(e)

0 comments on commit 98e27af

Please sign in to comment.