# Crawl errors

Starting a crawl can fail, a crawl can stop early, and each page can fail on its own.

## Three levels

- **The request.** A request that is not valid or cannot be paid for answers with an HTTP error and the one [error shape](https://millionshort.com/docs/errors#the-error-shape) every endpoint uses. No crawl is started.
- **The crawl.** A crawl that was started answers `200` when you poll it, for as long as its results are kept (7 days after it ended; then `404`). Its `status` and `stop_reason` say how it went, and a crawl that failed has an `error`.
- **Each page.** Every entry of `results` has `status: "ok"` or `status: "error"` with an `error` of its own. A URL that fails costs nothing, except a page a browser mode (`rendered`, `unblock`) found missing: it is charged and says `charged: true`.

## Request errors

| Status and code | When | Try next |
|---|---|---|
| `400 INVALID_PARAM` | A field the API does not take, a pattern that is not a valid regular expression, an unknown slug in a label list, `remove_top_sites` without `same_domain: false`, `mode: "cached"` with `same_domain: false` | Fix the request |
| `400 INVALID_PARAM`, with `details.max` | `max_pages` is over your plan's ceiling. `details.max` is the ceiling. (Over 25,000, the highest ceiling, the `400` has no `details.max`) | A smaller `max_pages` |
| `400 INVALID_PARAM` | A `cursor` on `GET /v1/crawl/{id}` that is not one we gave you | Use `next` as it came |
| `400 INVALID_PARAM`, with `details.reason` `URL_NOT_ALLOWED` | The start URL is not a public web page we will fetch | |
| `400 INVALID_PARAM` | A `webhook_id` that is not an `active` [endpoint](https://millionshort.com/docs/webhooks) of your team | Verify the endpoint first |
| `400 UNSUPPORTED_OPTION` | A mode the plan does not include, or one that is switched off; `json` on a plan without it | |
| `401 AUTH_MISSING_KEY`, `401 AUTH_INVALID_KEY` | No `Authorization` header, or a key that is malformed, revoked or expired | |
| `403 ROBOTS_DISALLOWED` | The site asked us not to fetch or serve it | Nothing: this is final |
| `404 JOB_NOT_FOUND` | `GET` or `DELETE` of a crawl that does not exist or belongs to another team. The two are not told apart | |
| `409 IDEMPOTENCY_CONFLICT` | The `Idempotency-Key` was used with a different request | A new key |
| `429 INSUFFICIENT_CREDITS` | The balance does not cover `max_pages` pages at the price of the mode | A smaller `max_pages` |
| `429 RATE_LIMITED` | The plan's number of open crawls is reached; or more than 120 polls in a minute; or, on `POST` and `DELETE`, your plan's requests a minute | When a crawl ends, or cancel one; after `retry_after_seconds` |

## Why a crawl stopped

`stop_reason` is `null` while the crawl runs. When it has ended:

| `stop_reason` | `status` | Meaning |
|---|---|---|
| `max_pages` | `completed` | The crawl was charged for as many pages as you asked for: the pages that came back and, in the browser modes, any page charged because the browser found it missing. `skipped` counts the URLs it found and did not try |
| `no_more_pages` | `completed` | Nothing was left to try within `max_depth` and the patterns |
| `site_daily_limit` | `completed` | Your team reached its daily limit for the site (2,000 fetches, sitemap files included). The pages that came back are kept |
| `too_many_failures` | `completed` | Too many URLs failed: a crawl tries at most 3 URLs for each page it may return, plus 20 |
| `cancelled` | `cancelled` | You cancelled it |
| `insufficient_credits` | `failed` | A part of the crawl could not be charged. The hold normally covers every page, so this is rare |
| `time_limit` | `failed` | The crawl did not end within 24 hours |
| `failed` | `failed` | Something went wrong on our side; or a `cached` crawl of a site whose robots.txt closes the start URL to our bot (`error.code` `ROBOTS_DISALLOWED`) or could not be read (`ROBOTS_UNAVAILABLE`, or another per-URL code when the check itself could not be made) |

In every case the pages that finished are kept and stay charged, and what is left of the hold is handed back.

## A crawl with no page at all

A crawl that ends without a single page that came back is `failed`, whatever its `stop_reason`, and its `error` carries the code of its first URL. The usual one:

```text
"status": "failed",
"completed": 0,
"credits_used": 0,
"error": {
  "code": "ROBOTS_DISALLOWED",
  "message": "No page came back. This site's robots.txt does not allow our bot to fetch this page."
}
```

It costs nothing. (The exception is a browser-mode crawl whose pages the browser found missing: those pages are charged, as [Pricing](https://millionshort.com/docs/crawl/pricing) says, and `credits_used` shows it.)

## Per-page errors

The codes are [Extract's](https://millionshort.com/docs/extract/errors#per-url-errors):

| Code | Meaning | Try next |
|---|---|---|
| `URL_NOT_ALLOWED` | Not a public web page we will fetch | |
| `ROBOTS_DISALLOWED` | The site's robots.txt does not allow our bot to fetch this page | |
| `ROBOTS_UNAVAILABLE` | robots.txt could not be read, so we did not fetch. The crawl tried five times | Later |
| `SITE_OPTED_OUT` | The site asked us not to fetch or serve it | |
| `NOT_IN_CACHE` | `cached` mode: we hold no copy of this page | `live` |
| `FETCH_FAILED` | The site did not answer usefully. A link to a page that does not exist ends here | |
| `TIMEOUT` | The site was too slow | Later |
| `TOO_LARGE` | The page is over 10 MiB | |
| `UNSUPPORTED_CONTENT_TYPE` | Not a kind of document we read | |
| `BLOCKED_BY_SITE` | The site refused our bot | `unblock` |
| `RENDER_FAILED` | `rendered` or `unblock` could not load the page | Later |
| `HOST_BUSY` | The site stayed busy for us for more than an hour | Later |
| `HOST_DAILY_LIMIT` | Your team reached its daily limit for this site | Tomorrow (UTC) |
| `CAPACITY` | `rendered` and `unblock` are at capacity | Later |

A crawl waits for a busy site and does not fail a page with `HOST_BUSY` at once: see [how a batch runs](https://millionshort.com/docs/extract/batch#how-a-batch-runs), which is how a crawl runs too.

## What not to work around

`ROBOTS_DISALLOWED` and `SITE_OPTED_OUT` are final: there is no option to ignore robots.txt, and no mode gets past a site's own choice. `BLOCKED_BY_SITE` is different. The site refused an automated request, and `unblock` is the mode for that, on the plans that include it.

## Notes on the crawl

- `unread_sources` on a crawl names a list of URLs that could not be read when it started: `sitemap` or `index`. The crawl went on with the links it found.
- A page with `filtered: true` is not an error. It was fetched, its labels did not match the lists you sent, and it comes back without content.
