Skip to content

OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.

Python

Improve S3/IBM COS error handling and logging

Edwin Jose54b10f018a2e
diff --git a/src/connectors/aws_s3/api.py b/src/connectors/aws_s3/api.py
index 2612ca698..178c78ab5 100644
--- a/src/connectors/aws_s3/api.py
+++ b/src/connectors/aws_s3/api.py
@@ -70,9 +70,10 @@ async def s3_configure(
try:
s3 = create_s3_resource(conn_config)
list(s3.buckets.all())
- except Exception as exc:
+ except Exception:
+ logger.exception("Failed to connect to S3 during credential test.")
return JSONResponse(
- {"error": f"Could not connect to S3: {exc}"},
+ {"error": "Could not connect to S3 with the provided configuration."},
status_code=400,
)
@@ -112,8 +113,9 @@ async def s3_list_buckets(
s3 = create_s3_resource(connection.config)
buckets = [b.name for b in s3.buckets.all()]
return JSONResponse({"buckets": buckets})
- except Exception as exc:
- return JSONResponse({"error": f"Failed to list buckets: {exc}"}, status_code=500)
+ except Exception:
+ logger.exception("Failed to list S3 buckets for connection %s", connection_id)
+ return JSONResponse({"error": "Failed to list buckets"}, status_code=500)
async def s3_bucket_status(
diff --git a/src/connectors/ibm_cos/api.py b/src/connectors/ibm_cos/api.py
index e6793f2f0..ee4ef97b8 100644
--- a/src/connectors/ibm_cos/api.py
+++ b/src/connectors/ibm_cos/api.py
@@ -135,7 +135,8 @@ async def ibm_cos_list_buckets(
cos = create_ibm_cos_client(cfg)
buckets = [b["Name"] for b in cos.list_buckets().get("Buckets", [])]
return JSONResponse({"buckets": buckets})
- except Exception as exc:
+ except Exception:
+ logger.exception("Failed to list IBM COS buckets for connection %s", connection_id)
return JSONResponse({"error": "Failed to list buckets"}, status_code=500)
@@ -161,9 +162,9 @@ async def ibm_cos_bucket_status(
cfg = connection.config
cos = create_ibm_cos_resource(cfg)
all_buckets = [b.name for b in cos.buckets.all()]
- except Exception as exc:
+ except Exception:
logger.exception("Failed to list IBM COS buckets for connection %s", connection_id)
- return JSONResponse({"error": f"Failed to list buckets: {exc}"}, status_code=500)
+ return JSONResponse({"error": "Failed to list buckets"}, status_code=500)
# 2. Count indexed documents per bucket from OpenSearch
ingested_counts: dict = {}