Skip to content

Commit

Permalink
added error AirportNotFoundError
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanExtreme002 committed Dec 23, 2023
1 parent 5c33083 commit 7afc74b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion python/FlightRadar24/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"""

__author__ = "Jean Loui Bernard Silva de Jesus"
__version__ = "1.3.15"
__version__ = "1.3.16"

from .api import FlightRadar24API, FlightTrackerConfig
from .entities import Airport, Entity, Flight
9 changes: 7 additions & 2 deletions python/FlightRadar24/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .core import Core
from .entities.airport import Airport
from .entities.flight import Flight
from .errors import LoginError
from .errors import AirportNotFoundError, LoginError
from .request import APIRequest


Expand Down Expand Up @@ -88,7 +88,12 @@ def get_airport(self, code: str) -> Airport:
:param code: ICAO or IATA of the airport
"""
response = APIRequest(Core.airport_data_url.format(code), headers = Core.json_headers)
return Airport(details=response.get_content()["details"])
content = response.get_content()

if not content or not isinstance(content, dict) or not content.get("details"):
raise AirportNotFoundError(f"Could not find an airport by the code '{code}'.");

return Airport(details=content["details"])

def get_airport_details(self, code: str, flight_limit: int = 100, page: int = 1) -> Dict:
"""
Expand Down
4 changes: 4 additions & 0 deletions python/FlightRadar24/errors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# -*- coding: utf-8 -*-

class AirportNotFoundError(Exception):
pass


class CloudflareError(Exception):
def __init__(self, message, response):
self.message = message
Expand Down

0 comments on commit 7afc74b

Please sign in to comment.