Skip to content

Commit

Permalink
Handle both unit and units kwargs to troubleshoot errors
Browse files Browse the repository at this point in the history
Prevent logging configured keys
Prevent logging test API missing config
  • Loading branch information
NeonDaniel committed May 6, 2024
1 parent 837fb9a commit a0fe428
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions neon_api_proxy/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ def init_service_instances(self, service_class_mapping: dict) -> dict:
api_key = self.config.get(item, {}).get("api_key") if self.config \
else None
try:
if api_key is None:
LOG.warning(f"No API key for {item} in {self.config}")
if api_key is None and item != 'api_test_endpoint':
LOG.warning(f"No API key for {item} in "
f"{list(self.config.keys())}")
service_mapping[item] = \
service_class_mapping[item](api_key=api_key)
except Exception as e:
Expand Down
4 changes: 2 additions & 2 deletions neon_api_proxy/services/owm_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def handle_query(self, **kwargs) -> dict:
lng = kwargs.get("lng", kwargs.get("lon"))
api = kwargs.get('api') or "onecall"
lang = kwargs.get('lang') or "en"
units = "metric" if kwargs.get("units") == "metric" else "imperial"
units = "metric" if kwargs.get("units", kwargs.get("unit")) == "metric" else "imperial"

if not all((lat, lng, units)):
return {"status_code": -1,
Expand All @@ -88,7 +88,7 @@ def _get_api_response(self, lat: str, lng: str, units: str,
except AssertionError as e:
raise ValueError(e)
if api != "onecall":
log_deprecation(f"{api} was requested but only `onecall` "
log_deprecation(f"`{api}` was requested but only `onecall` "
f"is supported", "1.0.0")
api = "onecall"
assert units in ("metric", "imperial", "standard")
Expand Down
2 changes: 1 addition & 1 deletion neon_api_proxy/services/wolfram_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _build_query_string(**kwargs) -> str:
query_params = dict()
query_params['i'] = kwargs.get("query")
query_params['units'] = kwargs.get("units") if \
kwargs.get("units") == "metric" else "imperial"
kwargs.get("units", kwargs.get("unit")) == "metric" else "imperial"
lat = kwargs.get("lat")
lng = kwargs.get("lng")
if kwargs.get("latlong"):
Expand Down

0 comments on commit a0fe428

Please sign in to comment.