Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Return 404 on IP not found #13

Closed
wants to merge 2 commits into from
Closed

Conversation

bvieira
Copy link

@bvieira bvieira commented Mar 26, 2018

if the IP is not found on maxmind db, we get code 200 as response.

curl "http://freegeoip.net/json/0.0.0.0"
{"ip":"0.0.0.0","country_code":"","country_name":"","region_code":"","region_name":"","city":"","zip_code":"","time_zone":"","latitude":0,"longitude":0,"metro_code":0}

wouldn't it be better if it return 404 instead of 200?

This PR create a toggle FAIL_ON_IP_NOTFOUND, false by default to maintain retrocompatibility, and if it's true, return 404 on IP not found.

@OlagStegan
Copy link

Strictly speaking "404 Not Found" is an incorrect response for an IP lookup.
For eg. /json/0.0.0.0
Unlike using the domain lookup
For eg. /json/google.con
where "404 Not Found" is correct.
It is not that the IP 0.0.0.0 is not a correct IP because it is, it is just that it is a "Reserved IP".

I believe that returning a 404 from a site or API would be misleading and could be better handled, much as it has been up to now with a JSON with blank entries.
Sorry

@bvieira
Copy link
Author

bvieira commented Mar 27, 2018

Make sense..

But can't we at least return a different status code? Parse the response and check if every attribute is empty don't seams right either.. this ip was not geolocated, so it's not ok either..

Partial content (206) don't look right either..

Bad request (400), Unprocessable Entity (422) maybe?

I would like to monitor this situation, but if it's exactly like the normal geolocated ips, I can't

@OlagStegan
Copy link

Sure. I'm all for a better descriptive response than "its all empty, so go figure.." but I am sure that the blunt and extremely negative status codes are the best way to handle this.
Perhaps, a descriptive field in the json denoting the type of the ip returned but that would require an extra db to build and maintain (unlikely "reserved" ip likely to change anytime soon but... who can predict? just look what google have done with the .dev TLD)
Using the 404 (and most status codes) simply indicates you don't want visitors at the moment what we have is not perfect and I'll agree with you that there must be a better way.

At the moment it is down to any user of the API to handle the response accordingly. 404, blank json or data json and then to display what is pertinent/format to their site.

@bvieira bvieira closed this Apr 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants