API returns HTTP 200 for invalid ICAO codes
JanC opened this issue · 4 comments
Hi,
when a client submits a non-existing icao code, the API returns correctly an error message
{
"Error": "Station Lookup Error: METAR not found for ABCD. There might not be a current report in ADDS",
"Meta": {
"Timestamp": "Sun, 18 Feb 2018 20:20:21 GMT"
}
}
but the HTTP code is 200.
curl -I 'https://avwx.rest/api/metar/ABCD'
HTTP/1.1 200 OK
Content-Length: 176
Content-Type: application/json
Server: gunicorn/19.7.1
Access-Control-Allow-Origin: *
Date: Sun, 18 Feb 2018 20:32:36 GMT
I believe the api.py
should handle this and return an appropriate error code to the client. In the if error:
case:
maybe simply:
if error:
resp = jsonify({'Error': error})
resp.status_code = 404
return resp
I agree. I’ll go through the API and find these error responses. However, I think the error code should be 400 in this case because the endpoint exists but the error arose because of client-supplied info.
The full range of status code pass throughs was a little more than expected, but d7547f7 should handle all of these cases for API endpoints. It also let me change if 'Error' in data:
to if code != 200:
which is more flexible.
thanks!
When supplying a invalid station icao code, the returned error is still 500 though:
curl http://localhost:8000/api/metar/ABC | jq
{
"message": "Internal Server Error"
}