Skip to content

Commit

Permalink
Error handling (#114)
Browse files Browse the repository at this point in the history
Co-authored-by: Luka Fontanilla <[email protected]>
  • Loading branch information
colin-roy-ehri and LukaFontanilla authored Oct 23, 2024
1 parent 2387174 commit 3c8f60b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
19 changes: 13 additions & 6 deletions explore-assistant-cloud-function/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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=<YOUR_PROJECT_ID>"
]
},
lookmlExamplesUndefinedErr: {
Expand All @@ -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: {
Expand Down

0 comments on commit 3c8f60b

Please sign in to comment.