Errors & status codes

countries.dev uses standard HTTP status codes. Learn what 200, 400, 404 and 429 mean, how errors are returned as JSON, and how to handle a missing country gracefully.

countries.dev uses conventional HTTP status codes and returns errors as a small JSON object.

Status codes

CodeMeaningWhen you'll see it
200OKThe request succeeded.
400Bad requestA parameter is invalid — e.g. a non-numeric value where a numeric code is expected.
404Not foundNothing matches — an unknown ISO code, an unmatched postal code, or a country with no results.
429Too many requestsYou hit the abuse ceiling. See Rate limits & caching.

Error shape

Errors come back as JSON with an error message:

{
  "error": "Country not found"
}

Handling errors

Check response.ok (or the status code) and branch on it:

const res = await fetch('https://countries.dev/alpha/ZZ');

if (res.status === 404) {
  // No country with that code — show a fallback.
} else if (res.ok) {
  const country = await res.json();
}

A 404 usually means the input didn't match anything (a typo'd ISO code, a postal code we don't cover) rather than a server problem — treat it as "no result", not "try again".

On this page