
# Errors

Every refusal is an [RFC 9457](https://www.rfc-editor.org/rfc/rfc9457) problem, sent as
`application/problem+json`:

```json
{
  "type": "https://developers.fincalc.com/problems/not-licensed",
  "title": "Calculator not licensed",
  "status": 403,
  "detail": "Your license does not include auto-loan-accelerated-payoff for the API."
}
```

Code against `type`, never `detail`: the detail is for people and may change. Each `type` is a page
here that says what it means and what to do.

| Status | Type |
|---|---|
| 400 | [`invalid-body`](/problems/invalid-body), [`unknown-include`](/problems/unknown-include), [`unsupported-locale`](/problems/unsupported-locale), [`invalid-lead`](/problems/invalid-lead) |
| 401 | [`unauthorized`](/problems/unauthorized) |
| 403 | [`institution-inactive`](/problems/institution-inactive), [`network-not-allowed`](/problems/network-not-allowed), [`insufficient-scope`](/problems/insufficient-scope), [`api-access-off`](/problems/api-access-off), [`not-licensed`](/problems/not-licensed), [`lead-capture-off`](/problems/lead-capture-off) |
| 404 | [`unknown-calculator`](/problems/unknown-calculator), [`unknown-lead`](/problems/unknown-lead) |
| 409 | [`consent-not-current`](/problems/consent-not-current) |
| 413 | [`body-too-large`](/problems/body-too-large) |
| 422 | [`invalid-inputs`](/problems/invalid-inputs): the calculator refused the inputs, and `errors` lists each one with a JSON Pointer to it, and a `hint` where one helps. For a lead: [`idempotency-key-reused`](/problems/idempotency-key-reused). |
| 429 | [`rate-limited`](/problems/rate-limited), [`quota-exhausted`](/problems/quota-exhausted), [`too-many-failed-keys`](/problems/too-many-failed-keys) |
| 503 | [`unavailable`](/problems/unavailable), [`busy`](/problems/busy) |

A 429 or 503 carries `Retry-After`, in seconds. Wait at least that long; retrying sooner only spends
your rate limit.

## Reading a refusal's body

Some HTTP clients treat a 4xx as an exception and keep the body out of sight, and the body is what says
what to fix. In Windows PowerShell 5.1, `Invoke-RestMethod` and `Invoke-WebRequest` throw on a 4xx: read
the problem from the error record, `$_.ErrorDetails.Message`, in a `catch` block. PowerShell 7 can keep
the answer instead, with `-SkipHttpErrorCheck` and `-StatusCodeVariable`:

```powershell
$answer = Invoke-RestMethod https://api.fincalc.com/v2/calculators/auto-loan-accelerated-payoff `
  -Method Post -Headers @{ Authorization = "Bearer $env:FINCALC_KEY" } `
  -ContentType "application/json" -Body '{"loanAmount": 25000}' `
  -SkipHttpErrorCheck -StatusCodeVariable status
if ($status -ge 400) { $answer.type; $answer.detail; $answer.errors }
```

`curl` prints the body whatever the status; add `--fail-with-body` to make it fail the command too.
