From ed6a4f185cb4a6265f131ffa8dd86edc4e90ec8a Mon Sep 17 00:00:00 2001 From: Ayyub I Date: Mon, 13 Nov 2023 19:53:28 -0600 Subject: [PATCH] modify update_supabase error handling --- packages/googlecloud/functions/getanswer/main.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/googlecloud/functions/getanswer/main.py b/packages/googlecloud/functions/getanswer/main.py index 0850dea5..9c723c92 100644 --- a/packages/googlecloud/functions/getanswer/main.py +++ b/packages/googlecloud/functions/getanswer/main.py @@ -23,10 +23,16 @@ supabase = create_client(supabase_url, supabase_key) def update_supabase(response, query, response_type): - # Assume you have a table named 'answers' with a column named 'answer' - response = supabase.table('cards').insert({'title': query, 'responses': response, 'card_type': response_type}).execute() - if response.error: - logging.error(f"Failed to update Supabase: {response.error}") + # Insert data into the Supabase table + result = supabase.table('cards').insert({'title': query, 'card_type': response_type, 'responses': response}).execute() + + # Check for errors in the response + if result.status_code != 200: # or another appropriate success code + # Log the error or handle it as per your application logic + logging.error(f"Failed to update Supabase: {result}") + else: + # Handle successful insertion + logging.info("Data successfully inserted into Supabase") @functions_framework.http def getanswer(request):