From fc45766fcc764e6be491b6a1f6657a79886d7f96 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Fri, 3 Nov 2023 15:49:39 +0530 Subject: [PATCH] fix: pr comments --- src/main/java/io/supertokens/webserver/RequestStats.java | 2 ++ src/main/java/io/supertokens/webserver/WebserverAPI.java | 2 +- src/test/java/io/supertokens/test/RequestStatsTest.java | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/supertokens/webserver/RequestStats.java b/src/main/java/io/supertokens/webserver/RequestStats.java index fcf3aec73..48f4e3f8f 100644 --- a/src/main/java/io/supertokens/webserver/RequestStats.java +++ b/src/main/java/io/supertokens/webserver/RequestStats.java @@ -97,6 +97,8 @@ public static RequestStats getInstance(Main main, AppIdentifier appIdentifier) t return (RequestStats) main.getResourceDistributor() .getResource(appIdentifier.getAsPublicTenantIdentifier(), RESOURCE_KEY); } catch (TenantOrAppNotFoundException e) { + // appIdentifier parameter is coming from the API request and hence we need to check if the app exists + // before creating a resource for it if (Multitenancy.getTenantInfo(main, appIdentifier.getAsPublicTenantIdentifier()) == null) { throw e; } diff --git a/src/main/java/io/supertokens/webserver/WebserverAPI.java b/src/main/java/io/supertokens/webserver/WebserverAPI.java index 99b177b7d..a94e04d83 100644 --- a/src/main/java/io/supertokens/webserver/WebserverAPI.java +++ b/src/main/java/io/supertokens/webserver/WebserverAPI.java @@ -484,7 +484,7 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws try { RequestStats.getInstance(main, tenantIdentifier.toAppIdentifier()).updateRequestStats(); } catch (TenantOrAppNotFoundException e) { - throw new IllegalStateException(e); // should never happen + // Ignore the error as we would have already sent the response for tenantNotFound } } diff --git a/src/test/java/io/supertokens/test/RequestStatsTest.java b/src/test/java/io/supertokens/test/RequestStatsTest.java index 3d432a663..807ef6e68 100644 --- a/src/test/java/io/supertokens/test/RequestStatsTest.java +++ b/src/test/java/io/supertokens/test/RequestStatsTest.java @@ -278,8 +278,8 @@ public void testWithNonExistantApp() throws Exception { 1000, null, Utils.getCdiVersionStringLatestForTests(), null); fail(); } catch (HttpResponseException e) { - assertEquals(500, e.statusCode); - assertEquals("Http error. Status Code: 500. Message: AppId or tenantId not found => Tenant with the following connectionURIDomain, appId and tenantId combination not found: (, a1, public)", e.getMessage()); + assertEquals(400, e.statusCode); + assertEquals("Http error. Status Code: 400. Message: AppId or tenantId not found => Tenant with the following connectionURIDomain, appId and tenantId combination not found: (, a1, public)", e.getMessage()); } process.kill();