Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion api/app/v1/endpoints/read/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
# limitations under the License.

import json
import logging

import asyncpg
from app import ANONYMOUS_VIEWER, AUTHORIZATION, REDIS
from app.db.asyncpg_db import get_pool
from app.db.redis_db import redis
Expand All @@ -24,6 +26,8 @@
from .query_parameters import CommonQueryParams, get_common_query_params
from .read import asyncpg_stream_results, wrapped_result_generator

logger = logging.getLogger(__name__)

v1 = APIRouter()

user = Header(default=None, include_in_schema=False)
Expand Down Expand Up @@ -97,7 +101,7 @@ async def get_commits(
media_type="application/json",
status_code=status.HTTP_200_OK,
)
except Exception as e:
except StopAsyncIteration:
return JSONResponse(
status_code=status.HTTP_404_NOT_FOUND,
content={
Expand All @@ -106,6 +110,29 @@ async def get_commits(
"message": "Not Found",
},
)
except (
asyncpg.PostgresConnectionError,
asyncpg.TooManyConnectionsError,
):
logger.exception("Database unavailable in get_commits")
return JSONResponse(
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
content={
"code": 503,
"type": "error",
"message": "Database temporarily unavailable",
},
)
except Exception:
logger.exception("Unexpected streaming error in get_commits")
return JSONResponse(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
content={
"code": 500,
"type": "error",
"message": "Internal server error",
},
)
except Exception as e:
return JSONResponse(
status_code=status.HTTP_400_BAD_REQUEST,
Expand Down
29 changes: 28 additions & 1 deletion api/app/v1/endpoints/read/datastream.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
# limitations under the License.

import json
import logging

import asyncpg
from app import ANONYMOUS_VIEWER, AUTHORIZATION, REDIS
from app.db.asyncpg_db import get_pool
from app.db.redis_db import redis
Expand All @@ -24,6 +26,8 @@
from .query_parameters import CommonQueryParams, get_common_query_params
from .read import asyncpg_stream_results, wrapped_result_generator

logger = logging.getLogger(__name__)

v1 = APIRouter()

user = Header(default=None, include_in_schema=False)
Expand Down Expand Up @@ -96,7 +100,7 @@ async def get_datastreams(
media_type="application/json",
status_code=status.HTTP_200_OK,
)
except Exception as e:
except StopAsyncIteration:
return JSONResponse(
status_code=status.HTTP_404_NOT_FOUND,
content={
Expand All @@ -105,6 +109,29 @@ async def get_datastreams(
"message": "Not Found",
},
)
except (
asyncpg.PostgresConnectionError,
asyncpg.TooManyConnectionsError,
):
logger.exception("Database unavailable in get_datastreams")
return JSONResponse(
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
content={
"code": 503,
"type": "error",
"message": "Database temporarily unavailable",
},
)
except Exception:
logger.exception("Unexpected streaming error in get_datastreams")
return JSONResponse(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
content={
"code": 500,
"type": "error",
"message": "Internal server error",
},
)
except Exception as e:
return JSONResponse(
status_code=status.HTTP_400_BAD_REQUEST,
Expand Down
29 changes: 28 additions & 1 deletion api/app/v1/endpoints/read/feature_of_interest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
# limitations under the License.

import json
import logging

import asyncpg
from app import ANONYMOUS_VIEWER, AUTHORIZATION, REDIS
from app.db.asyncpg_db import get_pool
from app.db.redis_db import redis
Expand All @@ -24,6 +26,8 @@
from .query_parameters import CommonQueryParams, get_common_query_params
from .read import asyncpg_stream_results, wrapped_result_generator

logger = logging.getLogger(__name__)

v1 = APIRouter()

user = Header(default=None, include_in_schema=False)
Expand Down Expand Up @@ -96,7 +100,7 @@ async def get_features_of_interest(
media_type="application/json",
status_code=status.HTTP_200_OK,
)
except Exception as e:
except StopAsyncIteration:
return JSONResponse(
status_code=status.HTTP_404_NOT_FOUND,
content={
Expand All @@ -105,6 +109,29 @@ async def get_features_of_interest(
"message": "Not Found",
},
)
except (
asyncpg.PostgresConnectionError,
asyncpg.TooManyConnectionsError,
):
logger.exception("Database unavailable in get_features_of_interest")
return JSONResponse(
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
content={
"code": 503,
"type": "error",
"message": "Database temporarily unavailable",
},
)
except Exception:
logger.exception("Unexpected streaming error in get_features_of_interest")
return JSONResponse(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
content={
"code": 500,
"type": "error",
"message": "Internal server error",
},
)
except Exception as e:
return JSONResponse(
status_code=status.HTTP_400_BAD_REQUEST,
Expand Down
29 changes: 28 additions & 1 deletion api/app/v1/endpoints/read/historical_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
# limitations under the License.

import json
import logging

import asyncpg
from app import ANONYMOUS_VIEWER, AUTHORIZATION, REDIS
from app.db.asyncpg_db import get_pool
from app.db.redis_db import redis
Expand All @@ -24,6 +26,8 @@
from .query_parameters import CommonQueryParams, get_common_query_params
from .read import asyncpg_stream_results, wrapped_result_generator

logger = logging.getLogger(__name__)

v1 = APIRouter()

user = Header(default=None, include_in_schema=False)
Expand Down Expand Up @@ -96,7 +100,7 @@ async def get_historical_locations(
media_type="application/json",
status_code=status.HTTP_200_OK,
)
except Exception as e:
except StopAsyncIteration:
return JSONResponse(
status_code=status.HTTP_404_NOT_FOUND,
content={
Expand All @@ -105,6 +109,29 @@ async def get_historical_locations(
"message": "Not Found",
},
)
except (
asyncpg.PostgresConnectionError,
asyncpg.TooManyConnectionsError,
):
logger.exception("Database unavailable in get_historical_locations")
return JSONResponse(
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
content={
"code": 503,
"type": "error",
"message": "Database temporarily unavailable",
},
)
except Exception:
logger.exception("Unexpected streaming error in get_historical_locations")
return JSONResponse(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
content={
"code": 500,
"type": "error",
"message": "Internal server error",
},
)
except Exception as e:
return JSONResponse(
status_code=status.HTTP_400_BAD_REQUEST,
Expand Down
29 changes: 28 additions & 1 deletion api/app/v1/endpoints/read/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
# limitations under the License.

import json
import logging

import asyncpg
from app import ANONYMOUS_VIEWER, AUTHORIZATION, REDIS
from app.db.asyncpg_db import get_pool
from app.db.redis_db import redis
Expand All @@ -24,6 +26,8 @@
from .query_parameters import CommonQueryParams, get_common_query_params
from .read import asyncpg_stream_results, wrapped_result_generator

logger = logging.getLogger(__name__)

v1 = APIRouter()

user = Header(default=None, include_in_schema=False)
Expand Down Expand Up @@ -96,7 +100,7 @@ async def get_locations(
media_type="application/json",
status_code=status.HTTP_200_OK,
)
except Exception as e:
except StopAsyncIteration:
return JSONResponse(
status_code=status.HTTP_404_NOT_FOUND,
content={
Expand All @@ -105,6 +109,29 @@ async def get_locations(
"message": "Not Found",
},
)
except (
asyncpg.PostgresConnectionError,
asyncpg.TooManyConnectionsError,
):
logger.exception("Database unavailable in get_locations")
return JSONResponse(
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
content={
"code": 503,
"type": "error",
"message": "Database temporarily unavailable",
},
)
except Exception:
logger.exception("Unexpected streaming error in get_locations")
return JSONResponse(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
content={
"code": 500,
"type": "error",
"message": "Internal server error",
},
)
except Exception as e:
return JSONResponse(
status_code=status.HTTP_400_BAD_REQUEST,
Expand Down
29 changes: 28 additions & 1 deletion api/app/v1/endpoints/read/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
# limitations under the License.

import json
import logging

import asyncpg
from app import ANONYMOUS_VIEWER, AUTHORIZATION, REDIS
from app.db.asyncpg_db import get_pool
from app.db.redis_db import redis
Expand All @@ -24,6 +26,8 @@
from .query_parameters import CommonQueryParams, get_common_query_params
from .read import asyncpg_stream_results, wrapped_result_generator

logger = logging.getLogger(__name__)

v1 = APIRouter()

user = Header(default=None, include_in_schema=False)
Expand Down Expand Up @@ -96,7 +100,7 @@ async def get_networks(
media_type="application/json",
status_code=status.HTTP_200_OK,
)
except Exception as e:
except StopAsyncIteration:
return JSONResponse(
status_code=status.HTTP_404_NOT_FOUND,
content={
Expand All @@ -105,6 +109,29 @@ async def get_networks(
"message": "Not Found",
},
)
except (
asyncpg.PostgresConnectionError,
asyncpg.TooManyConnectionsError,
):
logger.exception("Database unavailable in get_networks")
return JSONResponse(
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
content={
"code": 503,
"type": "error",
"message": "Database temporarily unavailable",
},
)
except Exception:
logger.exception("Unexpected streaming error in get_networks")
return JSONResponse(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
content={
"code": 500,
"type": "error",
"message": "Internal server error",
},
)
except Exception as e:
return JSONResponse(
status_code=status.HTTP_400_BAD_REQUEST,
Expand Down
Loading