mirror of
https://github.com/projecthorus/sondehub-infra.git
synced 2025-01-29 15:13:53 +00:00
Extra error handling (#95)
* Extra error handling * Terraform fmt [skip ci] * test Co-authored-by: xss <michaela@michaela.lgbt> Co-authored-by: TheSkorm <TheSkorm@users.noreply.github.com>
This commit is contained in:
parent
df07800d37
commit
05b838e6de
@ -348,7 +348,10 @@ def upload(event, context, orig_event):
|
||||
).total_seconds()
|
||||
except:
|
||||
pass
|
||||
# check if event is an array
|
||||
payloads = json.loads(event["body"])
|
||||
if type(payloads) != list:
|
||||
raise TypeError("Expecting list of payloads")
|
||||
to_sns = []
|
||||
first = False
|
||||
errors = []
|
||||
@ -451,6 +454,10 @@ def lambda_handler(event, context):
|
||||
response = {"statusCode": 400, "body": "Not valid json"}
|
||||
handle_error(json.dumps(response), orig_event, context.log_stream_name)
|
||||
return response
|
||||
except TypeError as e:
|
||||
response = {"statusCode": 400, "body": str(e)}
|
||||
handle_error(json.dumps(response), orig_event, context.log_stream_name)
|
||||
return response
|
||||
error_message = {
|
||||
"message": "some or all payloads could not be processed",
|
||||
"errors": errors
|
||||
@ -470,4 +477,5 @@ def lambda_handler(event, context):
|
||||
except:
|
||||
exc_type, exc_value, exc_traceback = sys.exc_info()
|
||||
handle_error("".join(traceback.format_exception(exc_type, exc_value, exc_traceback)), orig_event, context.log_stream_name)
|
||||
return {"statusCode": 400, "body": "Error processing request. Check payloads format."}
|
||||
|
||||
|
@ -3,42 +3,7 @@ import json
|
||||
import base64
|
||||
import gzip
|
||||
import uuid
|
||||
body = [
|
||||
{
|
||||
"software_name": "SondeMonitor",
|
||||
"software_version": "6.2.7.9",
|
||||
"uploader_callsign": "DL1XH",
|
||||
"uploader_position": ["53.762","10.471",0],
|
||||
"uploader_antenna": "5/8 GP",
|
||||
"time_received": "2022-11-16T23:55:44.195615Z",
|
||||
"datetime": "2022-11-16T23:56:00.000000Z",
|
||||
"manufacturer": "Vaisala",
|
||||
"type": "DFM",
|
||||
"serial": "T1240994",
|
||||
"subtype": "RS41-SGP",
|
||||
"frame": 5777,
|
||||
"lat": 54.6185,
|
||||
"lon": 11.23383,
|
||||
"alt": 1.77006,
|
||||
"temp": -71.0,
|
||||
"humidity": 3.3,
|
||||
"pressure": 29.57,
|
||||
"vel_v": 3.53743,
|
||||
"vel_h": 43.32368,
|
||||
"heading": 105.07473,
|
||||
"sats": 10,
|
||||
"batt": 2.5,
|
||||
"frequency": 402.5,
|
||||
"burst_timer": 65535,
|
||||
"snr": 23.1,
|
||||
"tx_frequency": 402.5,
|
||||
"user-agent": "Amazon CloudFront",
|
||||
"position": "54.6185,11.23383",
|
||||
"upload_time_delta": -1.969,
|
||||
"uploader_alt": 45.0,
|
||||
"dev": True
|
||||
}
|
||||
]
|
||||
body = {"software_name": "SondeHubUploader", "software_version": "1.0.0", "uploader_callsign": "SIMON2-14", "uploader_position": [53.23764, 7.74426, 7.0], "uploader_antenna": "5/8-Wave-J-Pole", "time_received": "2023-01-20T22:48:43.208780Z", "datetime": "2023-01-20T22:48:41.000000Z", "manufacturer": "Vaisala", "type": "RS41", "serial": "U1440085", "frame": 1759, "lat": 53.706667, "lon": 7.146944, "alt": 1295.7, "vel_v": 5.5, "vel_h": 6.2, "heading": 222.0, "sats": 10, "batt": 2.9, "frequency": 404.1, "rssi": 70.9}
|
||||
|
||||
compressed = BytesIO()
|
||||
with gzip.GzipFile(fileobj=compressed, mode='w') as f:
|
||||
|
Loading…
x
Reference in New Issue
Block a user