Skip to content

Commit 3cef54f

Browse files
committed
test: Dont initialize array in SupertokensSessionError class definition
1 parent a0d4daf commit 3cef54f

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

supertokens_python/recipe/session/exceptions.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def raise_token_theft_exception(user_id: str, session_handle: str) -> NoReturn:
2828
def raise_try_refresh_token_exception(ex: Union[str, Exception]) -> NoReturn:
2929
if isinstance(ex, SuperTokensError):
3030
raise ex
31+
32+
assert isinstance(ex, str)
3133
raise TryRefreshTokenError(ex) from None
3234

3335

@@ -40,12 +42,23 @@ def raise_unauthorised_exception(
4042
response_mutators = []
4143

4244
err = UnauthorisedError(msg, clear_tokens)
43-
err.response_mutators.extend(UnauthorisedError.response_mutators)
45+
err.extend_response_mutators(response_mutators)
46+
4447
raise err
4548

4649

4750
class SuperTokensSessionError(SuperTokensError):
48-
response_mutators: List[ResponseMutator] = []
51+
def __init__(
52+
self, msg: str, response_mutators: Optional[List[ResponseMutator]] = None
53+
):
54+
super().__init__(msg)
55+
self.response_mutators = response_mutators
56+
57+
def extend_response_mutators(self, response_mutators: List[ResponseMutator]):
58+
if self.response_mutators is None:
59+
self.response_mutators = []
60+
61+
self.response_mutators.extend(response_mutators)
4962

5063

5164
class TokenTheftError(SuperTokensSessionError):

supertokens_python/recipe/session/recipe.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,10 @@ async def handle_api_request(
221221
async def handle_error(
222222
self, request: BaseRequest, err: SuperTokensError, response: BaseResponse
223223
) -> BaseResponse:
224-
if isinstance(err, SuperTokensSessionError):
224+
if (
225+
isinstance(err, SuperTokensSessionError)
226+
and err.response_mutators is not None
227+
):
225228
for mutator in err.response_mutators:
226229
mutator(response)
227230

supertokens_python/recipe/session/session_request_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ async def refresh_session_in_request(
422422
)
423423
)
424424

425-
e.response_mutators.extend(response_mutators)
425+
e.extend_response_mutators(response_mutators)
426426
raise e
427427

428428
log_debug_message(

0 commit comments

Comments
 (0)