Don't crash when launch service provider is unknown

This commit is contained in:
Edward Betts 2023-12-23 11:36:30 +00:00
parent 697f317c5e
commit 6199c2affd

View file

@ -86,8 +86,14 @@ launch_providers = {
def summarize_launch(launch: Launch) -> Summary: def summarize_launch(launch: Launch) -> Summary:
"""Summarize rocket launch.""" """Summarize rocket launch."""
try:
launch_provider = launch["launch_service_provider"]["name"] launch_provider = launch["launch_service_provider"]["name"]
launch_provider_abbrev = launch_providers.get(launch_provider) launch_provider_abbrev = launch_providers.get(launch_provider)
launch_provider_type = launch["launch_service_provider"]["type"]
except (TypeError, IndexError):
launch_provider = None
launch_provider_abbrev = None
launch_provider_type = None
try: try:
net_precision = launch["net_precision"]["name"] net_precision = launch["net_precision"]["name"]
@ -109,7 +115,7 @@ def summarize_launch(launch: Launch) -> Summary:
"window_end": launch["window_end"], "window_end": launch["window_end"],
"launch_provider": launch_provider, "launch_provider": launch_provider,
"launch_provider_abbrev": launch_provider_abbrev, "launch_provider_abbrev": launch_provider_abbrev,
"launch_provider_type": launch["launch_service_provider"]["type"], "launch_provider_type": launch_provider_type,
"rocket": launch["rocket"]["configuration"]["full_name"], "rocket": launch["rocket"]["configuration"]["full_name"],
"mission": launch["mission"], "mission": launch["mission"],
"mission_name": (launch["mission"]["name"] if launch["mission"] else None), "mission_name": (launch["mission"]["name"] if launch["mission"] else None),