From 3c8f60bd37f3a6acd7e27ef5ef9e6e317b5e0d3f Mon Sep 17 00:00:00 2001 From: Colin Roy-Ehri <39524338+colin-roy-ehri@users.noreply.github.com> Date: Wed, 23 Oct 2024 09:39:20 -0600 Subject: [PATCH] Error handling (#114) Co-authored-by: Luka Fontanilla <51471651+LukaFontanilla@users.noreply.github.com> --- explore-assistant-cloud-function/main.py | 19 +++++++++++++------ .../src/components/Error/ErrorFallback.tsx | 6 ++++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/explore-assistant-cloud-function/main.py b/explore-assistant-cloud-function/main.py index 5bcdd17f..4076d9d7 100644 --- a/explore-assistant-cloud-function/main.py +++ b/explore-assistant-cloud-function/main.py @@ -122,14 +122,21 @@ def base(): contents = incoming_request.get("contents") parameters = incoming_request.get("parameters") if contents is None: - return "Missing 'contents' parameter", 400 + return "Missing 'contents' parameter", 400, get_response_headers(request) if not has_valid_signature(request): - return "Invalid signature", 403 - - response_text = generate_looker_query(contents, parameters) - - return response_text, 200, get_response_headers(request) + return "Invalid signature", 403, get_response_headers(request) + + try: + response_text = generate_looker_query(contents, parameters) + return response_text, 200, get_response_headers(request) + except Exception as e: + logging.error(f"Internal server error: {str(e)}") + return str(e), 500, get_response_headers(request) + + @app.errorhandler(500) + def internal_server_error(error): + return "Internal server error", 500, get_response_headers(request) return app diff --git a/explore-assistant-extension/src/components/Error/ErrorFallback.tsx b/explore-assistant-extension/src/components/Error/ErrorFallback.tsx index 3eaf94d1..d3b05f73 100644 --- a/explore-assistant-extension/src/components/Error/ErrorFallback.tsx +++ b/explore-assistant-extension/src/components/Error/ErrorFallback.tsx @@ -21,7 +21,8 @@ export default function Fallback({ error}: {error: any}) { diagnosis: "The error is likely related to your Look specific `.env` variables.", steps: [ "Make sure your user has access to this model and explore. At the very least with [`see_lookml`](https://cloud.google.com/looker/docs/admin-panel-users-roles#permissions_list) permissions.", - "Check the Connection environment variables. Do valid BQ connections by those names exist in your Looker instance?" + "Check the Connection environment variables. Do valid BQ connections by those names exist in your Looker instance?", + "Make sure the Vertex AI API is enabled if you're using a cloud function backend. Try: https://console.cloud.google.com/apis/library/aiplatform.googleapis.com?project=" ] }, lookmlExamplesUndefinedErr: { @@ -38,7 +39,8 @@ export default function Fallback({ error}: {error: any}) { "Please read the error message from BigQuery, the `SQLException` error will give you the reason.", "Ensure that the `BIGQUERY_EXAMPLE_PROMPTS_CONNECTION_NAME` env variable is valid and set to something that exists in Looker and that the examples can be accessed from this connection.", "Ensure that the `BIGQUERY_EXAMPLE_PROMPTS_DATASET_NAME` is set to the `project_id.dataset` name that contains the example tables.", - "Ensure that examples exist in both the [Examples and Refinement tables.](https://github.com/looker-open-source/looker-explore-assistant/tree/main/explore-assistant-examples)" + "Ensure that examples exist in both the [Examples and Refinement tables.](https://github.com/looker-open-source/looker-explore-assistant/tree/main/explore-assistant-examples)", + "If you are using the cloud backend, please remove VERTEX_BIGQUERY_MODEL_ID and VERTEX_BIGQUERY_EXPLORE_ID and try again." ] }, bigQueryModelErr: {