Skip to content

Errors#

Every error is an RFC 9457 problem document with a stable code. Branch on code, show detail to the people who can fix the request, and log request_id.

400 Bad Request · application/problem+json
{
  "type": "https://docs.surfacelens.app/reference/errors/#invalid_parameter",
  "title": "Invalid parameter",
  "status": 400,
  "code": "invalid_parameter",
  "detail": "radius must be between 1 and 20000 metres.",
  "request_id": "req_8Jw3Nd5kQ1ra",
  "errors": [
    { "parameter": "radius", "message": "Must be between 1 and 20000." }
  ]
}
code string
One of the codes below. New codes may be added in v1; treat an unknown code by its HTTP status.
detail string
One sentence about this request. Wording can change; do not parse it.
errors array
On invalid_parameter and invalid_body, one entry per problem, with parameter or a JSON Pointer in pointer.
request_id string
Also in the SurfaceLens-Request-Id header. Include it when you contact support.

Codes#

StatusCodeMeaning and what to doRetry
400invalid_parameterA path or query parameter is malformed or out of range. errors names it.No
400invalid_bodyThe JSON body is malformed or does not match the schema. errors points into it.No
401authentication_requiredNo key, or a key that does not exist. Check the Authorization: Bearer header.No
401key_revokedThe key was revoked. detail gives the time. Use another key of the application.No
403insufficient_scopeThe application lacks the scope the operation needs, or access to the feed. detail names the scope.No
403airport_not_permittedThe application is not granted this airport.No
404not_foundNo such resource, or not visible to this application. An entity of a type the application cannot read is also not_found.No
422time_out_of_rangeat, known_at or from is in the future, or older than the history this node holds. See retention.No
409conflictThe resource is not in a state that allows this request, such as pushing records to a draft feed.No
409idempotency_key_reusedThis Idempotency-Key was used in the last 24 hours with a different request. Use a new key for a new request.No
413payload_too_largeThe body is over 1 MiB, or a batch holds more than 500 records. Split it.No
429rate_limitedOver the key's request or stream limit. Wait for Retry-After.Yes
500internal_errorA fault on our side. It is logged against request_id.Yes
503not_primaryThis node cannot accept the write while it is standby and the primary is unreachable. detail gives the other node's base URL.Yes, on the other node
503unavailableThe node is overloaded or in maintenance (with Retry-After), or cannot reach the airport's home region (without it).Yes

Retrying#

Retry only the errors marked above, and network failures where no response arrived.

  • Wait for Retry-After when it is present. Otherwise back off exponentially from one second, with jitter, up to 30 seconds.
  • Retry POST requests only with the same Idempotency-Key as the first attempt, so a request that did succeed is not repeated. GET, PUT, DELETE and searches are safe to retry as they are. Pushing records is safe to retry because records are deduplicated by record_id.
  • A 503 unavailable without Retry-After, repeated, means the edge cannot be reached. Clients inside an airport with an on-premise node should then fail over.
Retry with backoff
async function withRetry(send: () => Promise<Response>, attempts = 5): Promise<Response> {
  for (let i = 0; ; i++) {
    let res: Response | undefined;
    try {
      res = await send();
      if (![429, 500, 502, 503, 504].includes(res.status)) return res;
    } catch (error) {
      if (i >= attempts - 1) throw error;
    }
    if (res && i >= attempts - 1) return res;
    const after = Number(res?.headers.get("Retry-After"));
    const wait = after > 0 ? after * 1000 : Math.min(30_000, 1000 * 2 ** i) * (0.5 + Math.random() / 2);
    await new Promise((r) => setTimeout(r, wait));
  }
}

Errors in streams#

An event stream that has started cannot change its status code. If the stream must end early, it sends a final event and closes:

event: stream.overflow
data: {"revision":48213990,"detail":"The client fell more than 10000 events behind."}

Reconnect with Last-Event-ID, as described in Subscribe to changes. Errors before the stream starts, such as 401 or 403, are ordinary problem documents.

Errors in batches#

Pushing records returns 200 when the batch was read, even if some records were rejected. Each result has its own status and errors; see Push records.