From 3f9b6d7078baf213ecf39b4d1eb9d717676ce79f Mon Sep 17 00:00:00 2001 From: Riku Oja Date: Tue, 28 Nov 2023 17:07:48 +0200 Subject: [PATCH] Temporarily raise exception to test lambda error handling --- .../arcgis_loader/arcgis_loader.py | 15 ++++++------ .../base_loader/base_loader.py | 23 ++++++++++++------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/backend/lambda_functions/arcgis_loader/arcgis_loader.py b/backend/lambda_functions/arcgis_loader/arcgis_loader.py index 7a9263b..1d5c4bb 100644 --- a/backend/lambda_functions/arcgis_loader/arcgis_loader.py +++ b/backend/lambda_functions/arcgis_loader/arcgis_loader.py @@ -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." @@ -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( diff --git a/backend/lambda_functions/base_loader/base_loader.py b/backend/lambda_functions/base_loader/base_loader.py index 9492f32..284774f 100644 --- a/backend/lambda_functions/base_loader/base_loader.py +++ b/backend/lambda_functions/base_loader/base_loader.py @@ -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 @@ -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