# Errors

> Every error code we return, why, and how to fix it.

**Error body, both directions**

```json
{ "error": { "code": "bad_signature", "message": "X-PR-Signature does not match timestamp.POST./events.body" } }
```

## Codes we return

| Code | Status | Cause | Fix |
|---|---|---|---|
| `unauthorized` | 401 | Missing or malformed `Authorization: Bearer` key, or an unknown key | Send `Authorization: Bearer prk_test_...` (or `prk_live_...`). Keys stop working when new ones are issued |
| `bad_signature` | 401 | `X-PR-Signature` does not match `timestamp.POST./events.body` (or `/supply`) | Sign the exact body you send, with the path `/events` or `/supply` and the secret for that environment |
| `stale_timestamp` | 401 | `X-PR-Timestamp` missing or more than 5 minutes from our clock | Sync your clock (NTP). Sign each try again with a fresh timestamp |
| `invalid_json` | 400 | Body is not JSON | Send a JSON object with `Content-Type: application/json` |
| `invalid_event` | 400 | A missing or wrong field (the message names it), an unknown event, `occurred_at` in the future or before we booked the trip, or a `stop_order` the trip does not have | Fix the field named in the message. Do not retry unchanged |
| `invalid_supply` | 400 | Supply report: a missing or wrong field | Fix the field named in the message |
| `inconsistent_counts` | 422 | Supply report: online over total, or on trip over online | Count again so `on_trip_drivers` ≤ `online_drivers` ≤ `total_drivers` |
| `unknown_trip` | 404 | No trip with that `pr_trip_id` for your account | Use the `pr_trip_id` from our booking, with the key of the account that got it |
| `trip_mismatch` | 400 | `partner_trip_id` does not match this `pr_trip_id` | Send the `partner_trip_id` you returned when we booked |
| `wrong_environment` | 403 | A live trip sent with a sandbox key, or a sandbox trip with a live key | Send live trips with `prk_live_` and sandbox trips with `prk_test_` |
| `wrong_pin` | 422 | Not the rider's code | Ask the driver to check it with the rider, then send `trip.started` again with a new `event_id` |
| `pin_locked` | 422 | 5 wrong codes. The trip cannot start | Stop. The rider contacts PerfectRide support |
| `retry_later` | 409 | The event came before the one it follows, or the trip changed while it was applied | Send the earlier event first, then retry with backoff |
| `complete_required` | 409 | A cash trip that has started can't be cancelled | Send `trip.completed` when it ends |
| `cancel_not_allowed` | 409 | After the driver arrived, a cash trip can only be cancelled as a rider no-show | Send `reason: "rider_no_show"` |
| `fee_not_supported` | 422 | Cash trips take no cancellation fee in the pilot | Send `cancellation_fee: 0` |
| `length_required` | 411 | No `Content-Length` header (chunked bodies are not accepted) | Send the body with a `Content-Length` header |
| `too_large` | 413 | Body over 64 KB | Send smaller events. Supply reports: at most 50 areas and 500 cells |
| `rate_limited` | 429 | Over 1,200 events or 60 supply reports a minute, or many refused keys from one address | Wait for `Retry-After`, then retry |
| `unavailable` | 503 | Supply report: we could not store it | Retry later |
| `not_found` | 404 | The Partner API is not switched on for this environment | Write to hello@perfectride.io |

> **Tip:** Retry only 409 `retry_later`, 429, 5xx and timeouts. Keep the same `event_id` and sign each try again.

## What you answer us

- A wrong key, signature or timestamp: 401 with the same error body.
- No driver for a quote: 200 `{ "available": false }`. It is not an error.
- A repeated `Idempotency-Key`: the same trip or cancellation, never a new one.

## In our test results

When we call you (portal tests, certification and live trips), a failed call shows one of these.

| Code | Cause | Fix |
|---|---|---|
| `timeout` | No answer within 2 seconds (quotes) or 8 seconds (other calls) | Answer faster. Queue slow work |
| `network` | We could not connect, or the host resolves to a private address | Use a public HTTPS host that answers without redirects |
| `bad_base_url` | Your base URL is not https | Save an https URL in the portal |
| `bad_response` | A 2xx whose body does not match the spec | Check the response in [API reference](https://docs.perfectride.io/docs/api-reference) |
| `http_<status>` | A non-2xx without an error body | Answer with `{ "error": { "code", "message" } }`, or fix the failure |
| Your own code | A non-2xx with your error body | Shown as you sent it |

## Next

- [Trip events](https://docs.perfectride.io/docs/trip-events.md): Tell PerfectRide what happens on each trip, in order, and handle our answers.
- [Keys and signing](https://docs.perfectride.io/docs/keys-and-signing.md): Which key goes where, and how every request is signed in both directions.
- [Support](https://docs.perfectride.io/docs/support.md): How to reach the PerfectRide partner team.

Source: https://docs.perfectride.io/docs/errors
