prufy
Skip to the page

APIErrors

API

Errors

Every response that isn't a success has the same body: a kind to switch on, a message written for a person, and how long to wait when waiting helps.

One shape

The body is always { error: { kind, message } }. kind is a fixed set of values, so code can branch on it. message says the same thing in plain words and names the fix, so it can go straight onto a screen. retryAfter appears only on errors that waiting fixes.

Waiting fixes it429 Too many requests
{
  "error": {
    "kind": "rate_limited",
    "message": "You can check again in 10 seconds.",
    "retryAfter": 10
  }
}
The input needs changing422 Unprocessable
{
  "error": {
    "kind": "reserved_tld",
    "message": ".localhost is set aside and can't be registered, so there's no public DNS to check. Enter a domain you've registered."
  }
}

The HTTP status is the broad category and kind is the exact reason. Branch on the kind: several share a status, and 10 statuses cover all 26 kinds.

Handling an error
const response = await fetch(url, options)
const data = await response.json()

if (!response.ok) {
  const { kind, message, retryAfter } = data.error
  switch (kind) {
    case "rate_limited":
    case "check_in_flight":
      // Waiting fixes these. retryAfter is in seconds.
      return retryIn(retryAfter)
    case "unauthorized":
      return startOver()
    default:
      // The message is written for a person. Show it as it is.
      return show(message)
  }
}

What isn't an error

A check that doesn't find the record is a 200. The request worked: we looked, and the answer is in view.phase and view.outcome. The same goes for a confirmation token that's already been used, and an unsubscribe pressed twice. Each answers 200 with a field that says what happened.

Headers

HeaderOnWhat it's for
x-request-idEvery responseNames this request in our logs. Send your own, up to 64 letters, digits, hyphens or underscores, and we use it. Otherwise we make one that starts with req_.
retry-afterErrors with retryAfterThe same number of seconds as the body, where HTTP clients expect it.
cache-controlEvery responseAlways no-store. A claim changes between reads, so nothing should cache one.

Every kind

The first eight are about the domain that was typed, and only come from routes that take one. Each route's page lists the kinds it can answer.

KindStatusWhat it meansWhat to do
empty422The domain was blank.Ask for a domain.
invalid_characters422The domain has characters a domain can't contain.Show the message. It names what to remove.
label_too_long422One part between dots is longer than 63 characters.Show the message.
too_long422The whole name is longer than 253 characters.Show the message.
ip_address422An IP address was sent where a domain belongs.Ask for the domain name.
reserved_tld422The ending is set aside, like .test or .localhost, so there's no public DNS to check.Ask for a registered domain.
public_suffix422The name is a suffix many people share, like co.uk.Ask for the domain under it.
single_label422The name has no dot, so there's no ending to look up.Ask for the full domain.
unauthorized401The request has no session, or one we don't recognise.Create a claim to start a session, and send its cookie.
not_found404Nothing is at this address for you. Another account's claim, an expired setup link and a development route in production all look like this.Check the id or token. Don't retry.
method_not_allowed405The address exists, but not with this method.Use a method from the Allow header. Only /api/v1 answers this way.
bad_request400The body isn't JSON, or doesn't have the shape the route expects.Fix the request. message names the first field to fix, and fields lists each one. Don't retry it as it is.
payload_too_large413The body is bigger than any route takes. The limit is 16 KB.Send only the fields the route lists. Don't retry the same body.
rate_limited429This has been done too often, too recently.Wait retryAfter seconds, then try again.
check_in_flight409Another check of this claim is running right now.Wait retryAfter seconds and read the claim. The other check's result will be there.
not_checkable409The claim is in a status where there's no record to look for or add.Read the claim. view.explanation.action says what's possible.
illegal_transition409The claim's status doesn't allow this. A verified claim can't be rotated, for one.Read the claim and offer what its status allows.
version_conflict409The claim changed while the request was running.Read the claim again, then retry if it still makes sense.
owner_conflict409Another account proved this domain at the same moment, and theirs finished first.Nothing. The claim stays pending and we check again on our own.
domain_connect_disabled404One-click setup is turned off on this server.Show the record to add by hand.
domain_connect_unavailable409One-click setup isn't possible for this domain or in this status.Show the record to add by hand.
email_unavailable503This server can't send email, or couldn't send to that address.Offer the link to copy, or ask them to check the address.
push_unavailable503This server has no push keys set up.Don't offer push. capabilities.pushPublicKey says so ahead of time.
timed_out503We didn't finish within 25 seconds. Anything already done, like a check, is kept.Wait retryAfter seconds, then read the claim before trying again.
unavailable503Something every route needs, like the database, isn't answering. Only the health check says this.Alert on it. Retry after retryAfter seconds.
internal_error500Something went wrong on our side. The details are in our logs, under the request id.Try again in a moment. If it keeps happening, send us the x-request-id.