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_parameterandinvalid_body, one entry per problem, withparameteror a JSON Pointer inpointer. - request_id string
- Also in the
SurfaceLens-Request-Idheader. Include it when you contact support.
Codes#
| Status | Code | Meaning and what to do | Retry |
|---|---|---|---|
| 400 | invalid_parameter | A path or query parameter is malformed or out of range. errors names it. | No |
| 400 | invalid_body | The JSON body is malformed or does not match the schema. errors points into it. | No |
| 401 | authentication_required | No key, or a key that does not exist. Check the Authorization: Bearer header. | No |
| 401 | key_revoked | The key was revoked. detail gives the time. Use another key of the application. | No |
| 403 | insufficient_scope | The application lacks the scope the operation needs, or access to the feed. detail names the scope. | No |
| 403 | airport_not_permitted | The application is not granted this airport. | No |
| 404 | not_found | No such resource, or not visible to this application. An entity of a type the application cannot read is also not_found. | No |
| 422 | time_out_of_range | at, known_at or from is in the future, or older than the history this node holds. See retention. | No |
| 409 | conflict | The resource is not in a state that allows this request, such as pushing records to a draft feed. | No |
| 409 | idempotency_key_reused | This Idempotency-Key was used in the last 24 hours with a different request. Use a new key for a new request. | No |
| 413 | payload_too_large | The body is over 1 MiB, or a batch holds more than 500 records. Split it. | No |
| 429 | rate_limited | Over the key's request or stream limit. Wait for Retry-After. | Yes |
| 500 | internal_error | A fault on our side. It is logged against request_id. | Yes |
| 503 | not_primary | This 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 |
| 503 | unavailable | The 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-Afterwhen it is present. Otherwise back off exponentially from one second, with jitter, up to 30 seconds. - Retry
POSTrequests only with the sameIdempotency-Keyas the first attempt, so a request that did succeed is not repeated.GET,PUT,DELETEand searches are safe to retry as they are. Pushing records is safe to retry because records are deduplicated byrecord_id. - A
503 unavailablewithoutRetry-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.