From ac46ecf32fefbd3ac24339b6bfbe610f3bc041a1 Mon Sep 17 00:00:00 2001 From: Taylor Jacovich Date: Fri, 20 Dec 2024 17:21:45 -0500 Subject: [PATCH] Add try block to catch anonymous clients that were cleared from the DB. (#3) --- apigateway/views.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/apigateway/views.py b/apigateway/views.py index 55aab5e..204f8b4 100644 --- a/apigateway/views.py +++ b/apigateway/views.py @@ -16,7 +16,7 @@ from werkzeug.security import gen_salt from apigateway import email_templates as templates -from apigateway import extensions, schemas +from apigateway import extensions, schemas, exceptions from apigateway.models import ( EmailChangeRequest, OAuth2Client, @@ -65,8 +65,11 @@ def get(self): client_id = current_token.client.client_id if client_id: - client, token = extensions.auth_service.load_client(client_id) - + try: + client, token = extensions.auth_service.load_client(client_id) + except exceptions.NoClientError: + client, token = extensions.auth_service.bootstrap_anonymous_user() + session["oauth_client"] = client.client_id # Check if the client_id is valid and that there is no client/user mismatch if not client_id or ( client.user_id != current_user.get_id()