Skip to content

Commit 248678b

Browse files
committed
fix: handle tenant not found error
1 parent 87b74e7 commit 248678b

File tree

18 files changed

+73
-34
lines changed

18 files changed

+73
-34
lines changed

supertokens_python/recipe/multitenancy/api/implementation.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ async def login_methods_get(
4444
tenant_id, user_context
4545
)
4646

47+
if tenant_config_res is None:
48+
raise Exception("Tenant not found")
49+
4750
provider_inputs_from_static = api_options.static_third_party_providers
4851
provider_configs_from_core = tenant_config_res.third_party.providers
4952

@@ -61,6 +64,11 @@ async def login_methods_get(
6164
client_type,
6265
user_context,
6366
)
67+
68+
if provider_instance is None:
69+
# because creating instance from the merged provider list itself
70+
raise Exception("Should never come here")
71+
6472
final_provider_list.append(
6573
ThirdPartyProvider(
6674
provider_instance.id, provider_instance.config.name

supertokens_python/recipe/multitenancy/asyncio/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ async def delete_tenant(
6161

6262
async def get_tenant(
6363
tenant_id: str, user_context: Optional[Dict[str, Any]] = None
64-
) -> GetTenantOkResult:
64+
) -> Optional[GetTenantOkResult]:
6565
if user_context is None:
6666
user_context = {}
6767
recipe = MultitenancyRecipe.get_instance()

supertokens_python/recipe/multitenancy/interfaces.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ async def delete_tenant(
217217
@abstractmethod
218218
async def get_tenant(
219219
self, tenant_id: str, user_context: Dict[str, Any]
220-
) -> GetTenantOkResult:
220+
) -> Optional[GetTenantOkResult]:
221221
pass
222222

223223
@abstractmethod

supertokens_python/recipe/multitenancy/recipe.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ async def login_methods_get(
216216
tenant_id, user_context
217217
)
218218

219+
if tenant_config is None:
220+
raise Exception("Tenant not found")
221+
219222
provider_inputs_from_static = api_options.static_third_party_providers
220223
provider_configs_from_core = tenant_config.third_party.providers
221224

@@ -233,6 +236,10 @@ async def login_methods_get(
233236
client_type,
234237
user_context,
235238
)
239+
240+
if provider_instance is None:
241+
raise Exception("Should never come here")
242+
236243
except ClientTypeNotFoundError:
237244
continue
238245
final_provider_list.append(

supertokens_python/recipe/multitenancy/recipe_implementation.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,16 @@ async def delete_tenant(
160160

161161
async def get_tenant(
162162
self, tenant_id: Optional[str], user_context: Dict[str, Any]
163-
) -> GetTenantOkResult:
163+
) -> Optional[GetTenantOkResult]:
164164
res = await self.querier.send_get_request(
165165
NormalisedURLPath(
166166
f"{tenant_id or DEFAULT_TENANT_ID}/recipe/multitenancy/tenant"
167167
),
168168
)
169169

170+
if res["status"] == "TENANT_NOT_FOUND_ERROR":
171+
return None
172+
170173
tenant_config = parse_tenant_config(res)
171174

172175
return GetTenantOkResult(

supertokens_python/recipe/thirdparty/api/authorisation_url.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
if TYPE_CHECKING:
2020
from supertokens_python.recipe.thirdparty.interfaces import APIOptions, APIInterface
2121

22-
from supertokens_python.exceptions import raise_bad_input_exception
22+
from supertokens_python.exceptions import raise_bad_input_exception, BadInputError
2323
from supertokens_python.utils import send_200_response
2424

2525

@@ -53,7 +53,12 @@ async def handle_authorisation_url_api(
5353
user_context=user_context,
5454
)
5555

56-
provider = provider_response.provider
56+
if provider_response is None:
57+
raise BadInputError(
58+
f"the provider {third_party_id} could not be found in the configuration"
59+
)
60+
61+
provider = provider_response
5762
result = await api_implementation.authorisation_url_get(
5863
provider=provider,
5964
redirect_uri_on_provider_dashboard=redirect_uri_on_provider_dashboard,

supertokens_python/recipe/thirdparty/api/signinup.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
if TYPE_CHECKING:
2020
from supertokens_python.recipe.thirdparty.interfaces import APIOptions, APIInterface
2121

22-
from supertokens_python.exceptions import raise_bad_input_exception
22+
from supertokens_python.exceptions import raise_bad_input_exception, BadInputError
2323
from supertokens_python.utils import send_200_response
2424

2525

@@ -64,7 +64,12 @@ async def handle_sign_in_up_api(
6464
user_context=user_context,
6565
)
6666

67-
provider = provider_response.provider
67+
if provider_response is None:
68+
raise BadInputError(
69+
f"the provider {third_party_id} could not be found in the configuration"
70+
)
71+
72+
provider = provider_response
6873

6974
result = await api_implementation.sign_in_up_post(
7075
provider=provider,

supertokens_python/recipe/thirdparty/interfaces.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ async def get_provider(
114114
client_type: Optional[str],
115115
tenant_id: str,
116116
user_context: Dict[str, Any],
117-
) -> GetProviderOkResult:
117+
) -> Optional[Provider]:
118118
pass
119119

120120

supertokens_python/recipe/thirdparty/providers/config_utils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,11 @@ async def find_and_create_provider_instance(
262262
third_party_id: str,
263263
client_type: Optional[str],
264264
user_context: Dict[str, Any],
265-
) -> Provider:
265+
) -> Optional[Provider]:
266266
for provider_input in providers:
267267
if provider_input.config.third_party_id == third_party_id:
268268
provider_instance = create_provider(provider_input)
269269
await fetch_and_set_config(provider_instance, client_type, user_context)
270270
return provider_instance
271271

272-
raise Exception(
273-
f"the provider {third_party_id} could not be found in the configuration"
274-
)
272+
return None

supertokens_python/recipe/thirdparty/recipe_implementation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from supertokens_python.querier import Querier
2828

2929
from .interfaces import (
30-
GetProviderOkResult,
3130
ManuallyCreateOrUpdateUserOkResult,
3231
RecipeInterface,
3332
SignInUpOkResult,
@@ -189,6 +188,9 @@ async def get_provider(
189188
user_context=user_context,
190189
)
191190

191+
if tenant_config is None:
192+
raise Exception("Tenant not found")
193+
192194
merged_providers = merge_providers_from_core_and_static(
193195
provider_configs_from_core=tenant_config.third_party.providers,
194196
provider_inputs_from_static=self.providers,
@@ -198,6 +200,4 @@ async def get_provider(
198200
merged_providers, third_party_id, client_type, user_context
199201
)
200202

201-
return GetProviderOkResult(
202-
provider,
203-
)
203+
return provider

0 commit comments

Comments
 (0)