Skip to content

Commit

Permalink
Error handling around query to fetch file metadata for consignment in…
Browse files Browse the repository at this point in the history
… consignment indexing lambda
  • Loading branch information
anthonyhashemi committed Dec 11, 2024
1 parent 1dd0aca commit 8ce10b1
Showing 1 changed file with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
from typing import Dict, List, Optional, Tuple, Union

import pg8000
from opensearchpy import OpenSearch, RequestsHttpConnection
from requests_aws4auth import AWS4Auth
from sqlalchemy import create_engine, text
Expand Down Expand Up @@ -170,18 +171,17 @@ def _fetch_files_in_consignment(
c."ConsignmentReference" = :consignment_reference
AND f."FileType" = 'File';
"""
# try:
# result = session.execute(
# text(query), {"consignment_reference": consignment_reference}
# ).fetchall()
# except pg8000.Error as e:
# raise Exception(f"Database query failed: {e}")
# finally:
# session.close()

result = session.execute(
text(query), {"consignment_reference": consignment_reference}
).fetchall()
try:
result = session.execute(
text(query), {"consignment_reference": consignment_reference}
).fetchall()
except pg8000.Error as e:
logger.error(
f"Failed to retrieve file metadata from database for consignment reference: {consignment_reference}"
)
session.close()
raise e

session.close()

# Process query results
Expand Down

0 comments on commit 8ce10b1

Please sign in to comment.