Handle errors
Every failure answers one question first: did it book? There are four answers: it may have booked, it is not confirmed, nothing was booked, or check first. Each one tells you what to do next.
How a failure looks
A failed drive answers status: "failed" with an error_code you can branch on, an error sentence for people, and a failure_class. terminal means this attempt is over. retryable_elsewhere means the site blocked Ophelia and nothing was committed: try again after Retry-After.
A 409 means this request failed. Do not send the same request again. Whether a new attempt is fine depends on the code, as the groups below say. A new attempt always takes a new idempotency_key: the same key answers the first answer again, a failure included.
Requests refused before anything runs use shorter bodies. {"error_code", "error"} carries the code in error_code, as for invalid_input, wrong_key_environment and no_organization. {"error": "invalid request body", "field", "detail"} names a field. Five codes sit in error itself, with no error_code: insufficient_scope, rate_limited, unauthorized, billing_required and billing_check_unavailable. Every shape is on Request rules, and every code on Statuses and error codes.
May have booked: stop and tell the person
409 not_confirmed_after_otp409 transaction_status_unknown409 booked_a_different_entityerror, the place and the time.GET /v3/bookings/{booking_id} reads the booking as it stands, with its ids and error.Not confirmed: almost certainly not booked
The pause ended before its code was typed, so the booking was almost certainly not made. v3 cannot confirm that. Check with the site if it matters. Then you may start a new booking with a new idempotency_key.
410 attempt_expiredGET /v3/bookings/{booking_id} reads failed with the same code.200 attempt_abandonedPauses have their own page: When a drive pauses.
Nothing was booked: fix it and try again
Every 400, 404, 422, 502 and 503 booked nothing, and so did the 409 codes below: each one is answered before any press that could book. Fix what the code names and try again with a new idempotency_key.
400 invalid_input or a field400 wrong_id_namespaceent_ and off_ ids v3 gave you.400 offer_entity_mismatchoffer_id belongs to another entity.400 ambiguous_verticalvertical (GET /v3/verticals).404 unknown_entity, unknown_offer, unknown_booking, unknown_attempt422 needs_inputmissing lists it. It can come after a drive ran; nothing was pressed. Send again with what missing lists. See When a drive pauses.422 max_total_required401, 403{"error": "insufficient_scope", "required_scope", "accepted_scopes"}. A site not switched on for the key reads 403 merchant_not_enabled_for_key, with allowed_sites. See Keys and scopes.402 "error": "billing_required""error": "free_tier_exhausted": switch to a live key with billing.no_site, unresolvable_site, private_addresssite.no_results, search_error, term_not_applied, location_not_applied, no_availabilityerror carries the site's words. See Find something.offer_gone, offer_expiredexpires_at. Read availability again for a fresh offer_id.entity_not_reachedunaddressable_entity, no_bookable_action, no_action_found, not_bookable_herecommitment_refusedmax_commitment does not fit the route: a search or availability read takes read or begin, a booking takes begin or commit.booking_errorbooking report says where.over_max_total, total_unreadable, cart_mismatch, currency_mismatch, variant_unavailable, selection_unconfirmed, out_of_stock, address_rejected, payment_method_unavailable, payment_link_expiredorder_refusedcard_declinedquote_unavailablebegin, so it was not run. Nothing was pressed.drive_lost503 drive_capacityRetry-After seconds (60).503 with failure_class: "retryable_elsewhere"Retry-After seconds (30).503 v3_disabled, billing_check_unavailable502search_nav_failed). Nothing was committed. Send it again.Always wait at least Retry-After seconds before you try again.
429 "error": "rate_limited"Retry-After seconds.429 site_pacedSome routes share one budget. Bookings and POST /v3/sessions share 10 per 5 minutes, and the two continue routes share 20, so connecting accounts uses up bookings. The budgets are on Rate limits.
Check first: any other failure at commit
Any other failure on a booking at commit does not say when it happened. That includes timeout, runner_error, unknown_status, session_expired, card_fill_failed, the otp_ codes, and the failures on Ophelia's side. Read GET /v3/bookings/{booking_id} and check with the site before you book again. Do not tell the person nothing was booked.
The same goes for 500 with error_code: "internal" on a booking at commit. (500 with "error": "rate limiter unavailable" is answered before anything runs, so nothing was booked.)
A booking at begin, a search and an availability read never press a final button, so these codes booked nothing there. The one exception is the alarm below.
begin answer carries ALERT_BOOKING_CREATED in its booking report, the drive landed on a confirmation anyway. A booking may have been made that you did not authorize. Tell the person and check with the site.processing with continue_in_flight is not a failure: a code is still being entered. Read GET /v3/bookings/{booking_id} and do not resend the code.
If your client times out
A booking call can stay open for minutes. If your client gives up on POST /v3/bookings, send the same request with the same idempotency_key. You get the booking as it stands, processing while the drive runs, and never a second booking.
While a booking reads processing, read GET /v3/bookings/{booking_id} again until it changes, or let a webhook tell you.
Next: Test on the practice site.