Skip to content

Commit

Permalink
Temporarily raise exception to test lambda error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Rikuoja committed Nov 28, 2023
1 parent 1f2af30 commit 3f9b6d7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
15 changes: 8 additions & 7 deletions backend/lambda_functions/arcgis_loader/arcgis_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def get_features(self) -> FeatureCollection: # type: ignore[override]
)
# Some arcgis services might be down for maintenance. Don't let this
# get in the way of importing other data.
if r.status_code == 503:
if r.status_code != 200:
LOGGER.warn(
f"ArcGIS service {url}/{service_name} is down at the "
"moment. Skipping this service."
Expand All @@ -172,12 +172,13 @@ def get_features(self) -> FeatureCollection: # type: ignore[override]
for layer in layer_list
if layer["name"] == layer_name
]
if not layer_ids:
LOGGER.warn(
f"Layer {layer_name} not found in source. Skipping "
"this layer."
)
continue
# TODO: commented to cause exception in case of missing layers
# if not layer_ids:
# LOGGER.warn(
# f"Layer {layer_name} not found in source. Skipping "
# "this layer."
# )
# continue
layer_id = layer_ids[0]
LOGGER.debug(f"Querying layer {layer_name}...")
r = requests.get(
Expand Down
23 changes: 15 additions & 8 deletions backend/lambda_functions/base_loader/base_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import json
import logging
import os
import sys
import traceback

# import sys
# import traceback
from typing import Any, Dict, List, Optional, Type, TypedDict, Union

import boto3
Expand Down Expand Up @@ -328,11 +329,17 @@ def base_handler(event: Event, loader_cls: type) -> Response:
response["body"] = json.dumps(msg)

except Exception:
response["statusCode"] = 500

exc_info = sys.exc_info()
exc_string = "".join(traceback.format_exception(*exc_info))
response["body"] = exc_string
LOGGER.exception(exc_string)
raise Exception
# # TODO: do something about this. Apparently lambda 500 does not mean a
# # function error, so we shouldn't return 500 as response. Lambda runtime
# # will still think this is a successful run, go figure, because it didn't
# # catch the error itself.
# # https://docs.aws.amazon.com/lambda/latest/dg/python-exceptions.html
# response["header"] = {"X-Amz-Function-Error": ""}

# exc_info = sys.exc_info()
# exc_string = "".join(traceback.format_exception(*exc_info))
# response["body"] = exc_string
# LOGGER.exception(exc_string)

return response

0 comments on commit 3f9b6d7

Please sign in to comment.