Errors

Every error has an HTTP status, a fixed code for your program and a message for people.

Format

Errors always come as JSON in this shape:

JSON
{
  "error": {
    "code": "invalid_request",
    "message": "limit must be a number between 1 and 20"
  }
}
FieldDescription
codeFixed code. This is what your program reacts to.
messageExplanation for developers, in English. The wording may change, do not parse it.

All codes

HTTPCodeMeaningWhat to do
400invalid_requestA parameter is missing or invalid. The message names it, like q is required or Unknown type "house".Fix the request, do not retry
400secret_key_in_urlSecret key sk_ sent as ?key= in the URLSend it as Authorization: Bearer <key> and rotate it, it may be in a log
401missing_keyNo key was sentSend Authorization: Bearer <key> (public keys also as ?key=)
401invalid_keyWe do not know this key, or it was deletedCheck the key in the dashboard
403origin_not_allowedA public key used from an origin that is not listed, or with no origin at all (for example from a server)Add the origin to the key, or use an sk_ key on servers
404not_foundThis path does not existCheck the URL: /v1/search or /v1/reverse
405method_not_allowedA method other than GETUse GET
429rate_limitedToo many requests per minuteWait Retry-After seconds, then retry
429quota_exceededThe monthly quota (Free) or your budget for extra requests (paid plans) is used upRaise the budget, change plans or wait for the next month. Retrying does not help.
500internal_errorUnexpected error on our sideTry again later
502upstream_errorThe search index is unreachable or did not answer within 8 secondsRetry after a pause

Retry or not

  • 4xx except 429: the request itself is wrong. Retrying gives the same result.
  • 429 rate_limited: wait the seconds from Retry-After. The Web Component and autocomplete() only send the latest request while someone types anyway.
  • 429 quota_exceeded: do not retry. Show your users a plain text field so the form keeps working.
  • 5xx: retry with growing pauses, for example after 1, 2 and 4 seconds.

In the libraries

All libraries throw their own exception with HTTP status and code when the API returns an error.

JavaScript
import { Findort, FindortError } from 'findort';

try {
  await findort.search('Bern');
} catch (e) {
  if (e instanceof FindortError && e.code === 'quota_exceeded') showPlainInput();
  else throw e;
}
PHP
try {
    $findort->search('Bern');
} catch (Findort\FindortException $e) {
    echo $e->getCode();     // 429 (HTTP status)
    echo $e->errorCode;     // quota_exceeded
    echo $e->getMessage();
}
Python
from findort import FindortError

try:
    findort.search("Bern")
except FindortError as e:
    print(e.status, e.code, e)  # 429 quota_exceeded ...

Extra codes from the libraries:

CodeWhen
network_errorPHP and Python: server unreachable, status 0
http_errorA response without readable JSON, for example from a proxy. The message contains the HTTP status.

In JavaScript, network errors and timeouts throw the error from fetch (TypeError, AbortError or TimeoutError), not FindortError.

In the Web Component

<findort-search> fires a findort-error event on errors. e.detail.error is the error from above.

JavaScript
el.addEventListener('findort-error', (e) => {
  console.warn(e.detail.error.code, e.detail.error.message);
});