avwx-rest / avwx-api

REST API for parsing aviation weather data
https://avwx.rest
MIT License
71 stars 89 forks source link

Server error on coordinates lookup with info flag #4

Closed JanC closed 6 years ago

JanC commented 6 years ago

When a metar report is looked up with the info option by coordinates in the geonames API but the found station does not exist on the AVWX-Engine, the API returns a HTTP 500

Request with the info option

curl -s  https://avwx.rest/api/metar//32.865,-114.393?options=info | jq
{
  "message": "Internal Server Error"
}

Same request without the info option:

curl -s https://avwx.rest/api/metar//32.865,-114.393 | jq

{
  "Altimeter": "3023",
  "Cloud-List": [],
  "Dewpoint": "M02",
  "Flight-Rules": "VFR",
  "Meta": {
    "Cache-Timestamp": "Fri, 23 Feb 2018 13:59:34 GMT",
    "Timestamp": "Fri, 23 Feb 2018 14:01:09 GMT"
  },
  "Other-List": [],
  "Raw-Report": "KLGF 221855Z AUTO 27009G14KT 250V310 10SM SKC 15/M02 A3023",
  "Remarks": "",
  "Remarks-Info": {},
  "Runway-Vis-List": [],
  "Station": "KLGF",
  "Temperature": "15",
  "Time": "221855Z",
  "Units": {
    "Altimeter": "inHg",
    "Altitude": "ft",
    "Temperature": "C",
    "Visibility": "sm",
    "Wind-Speed": "kt"
  },
  "Visibility": "10",
  "Wind-Direction": "270",
  "Wind-Gust": "14",
  "Wind-Speed": "09",
  "Wind-Variable-Dir": [
    "250",
    "310"
  ]
}

In this case, I would give priority to the metar report and return an empty Info json.

https://github.com/flyinactor91/AVWX-API/blob/bed76e4960d46420d2fdcfe424fa814182c2760c/avwx_api/handling.py#L133-L135

if 'info' in opts:
    try:
        resp['Info'] = avwx.Report(station).station_info
    except Exception as e:
        resp['Info'] = {}
return resp
JanC commented 6 years ago

strange, it's not happening anymore

devdupont commented 6 years ago

Either way, I added a check in https://github.com/flyinactor91/AVWX-API/commit/e45b6fcd266d5692c4b1a87173d72987e6c4ec7c for avwx.exceptions.BadStation which is what the avwx library raises when the station info is unavailable. Not sure why it flipped, but a good try/except block anyway.