Errors
When a v3 request fails, the API answers with an HTTP status and a JSON body in the standard problem format (RFC 9457). Every body has a stable code and a type link to the page that explains it.
The error body
Errors from the v3 REST routes have the content type application/problem+json. A successful response is application/json.
- Name
type- Type
- string
- Description
A link to the page for this error, for example
https://docs.finlight.me/errors/validation-failed. It is thecodein lower case with-instead of_.
- Name
title- Type
- string
- Description
A short, readable name of the error, such as
Validation failed.
- Name
status- Type
- integer
- Description
The HTTP status, the same as on the response.
- Name
detail- Type
- string
- Description
A readable explanation of this case. The text can change. Do not parse it.
- Name
code- Type
- string
- Description
The error code, such as
VALIDATION_FAILED. This is the value to branch on. The list can grow.
- Name
requestId- Type
- string
- Description
The
X-Request-Idheader you sent. Without one, the server makes an id in the formreq_<uuid>. Send it to support when you report a problem.
- Name
errors- Type
- array
- Description
Only on validation and cursor errors. One entry per problem, each with
field(the request field),issue(a readable text) and, for fields with a fixed list of values,allowedValues.
- Name
limitType- Type
- string
- Description
Only on
RATE_LIMITED. Which limit you hit:monthlyorburst. The list can grow.
Example error body
{
"type": "https://docs.finlight.me/errors/validation-failed",
"title": "Validation failed",
"status": 400,
"detail": "1 request field is not valid.",
"code": "VALIDATION_FAILED",
"requestId": "req-123",
"errors": [
{
"field": "eventTypes",
"issue": "each value in eventTypes must be one of the following values: earnings, guidance, mna, ...",
"allowedValues": ["earnings", "guidance", "mna", "..."]
}
]
}
The request id is only in error bodies. It is not sent back as a response header, and successful responses do not contain it.
Error codes
| Code | HTTP | When | Retry? |
|---|---|---|---|
VALIDATION_FAILED | 400 | A request field or the query is not valid. | No. Fix the request. |
CURSOR_INVALID | 400 | The cursor cannot be read. | No. Start the search again without a cursor. |
CURSOR_MISMATCH | 400 | The sort or the filters changed since the cursor was issued. | No. Send the same body as on the first page. |
UNAUTHORIZED | 401 | The API key is missing or wrong. | No. Fix the key. |
FORBIDDEN | 403 | Your plan does not include company data (/v3/companies). | No. Upgrade your plan. |
NOT_FOUND | 404 | No article or company for this id or link. | No. |
RATE_LIMITED | 429 | Monthly credits used up, or too many requests in 10 seconds. | Burst: once, after Retry-After. Monthly: no. |
INTERNAL_ERROR | 500 | Something failed on our side. | Yes, with backoff. |
The payment required page exists for completeness. The API does not send that code today.
v3 never answers 422. Field errors that v1 and v2 answer with 422 come back as 400 VALIDATION_FAILED on v3.
Branch on the code
- Use
codeto decide what to do. UselimitTypeto tell the two kinds of429apart. - Do not branch on
titleordetail. Their wording can change. - Treat an unknown
codeas a general error with the HTTP status. New codes can be added. - Log
requestIdwith every error. Support can find your request with it.
Responses that are not problem+json
Two failures happen before the v3 error handling runs. They come back as application/json in a simpler form, {statusCode, message, error}:
| Case | Status | Body |
|---|---|---|
| The request body is not valid JSON | 400 | {"message":"Unexpected end of JSON input","error":"Bad Request","statusCode":400} |
The route does not exist, for example GET /v3/nope | 404 | {"message":"Cannot GET /v3/nope","error":"Not Found","statusCode":404} |
A proxy in front of the API can also answer with a body that is not JSON at all, for example an HTML page with status 502. When there is no code, fall back to the HTTP status and treat a 5xx as retryable. The client libraries do this for you.
Errors in the client libraries
Every client library turns an error answer into one API error type with the same fields: status, code, title, detail, requestId, errors and apiKind. Each code has its own subclass in languages that use exception classes:
| Code | apiKind | TypeScript, Python, Ruby | .NET, Java, PHP | Go APIKind | Rust api_kind() |
|---|---|---|---|---|---|
VALIDATION_FAILED | validation_failed | ValidationFailedError | ValidationFailedException | APIKindValidationFailed | ApiErrorKind::ValidationFailed |
CURSOR_INVALID | cursor_invalid | CursorInvalidError | CursorInvalidException | APIKindCursorInvalid | ApiErrorKind::CursorInvalid |
CURSOR_MISMATCH | cursor_mismatch | CursorMismatchError | CursorMismatchException | APIKindCursorMismatch | ApiErrorKind::CursorMismatch |
UNAUTHORIZED | unauthorized | UnauthorizedError | UnauthorizedException | APIKindUnauthorized | ApiErrorKind::Unauthorized |
FORBIDDEN | forbidden | ForbiddenError | ForbiddenException | APIKindForbidden | ApiErrorKind::Forbidden |
NOT_FOUND | not_found | NotFoundError | NotFoundException | APIKindNotFound | ApiErrorKind::NotFound |
RATE_LIMITED | rate_limited | RateLimitedError | RateLimitedException | APIKindRateLimited | ApiErrorKind::RateLimited |
INTERNAL_ERROR | internal_error | InternalServerError | InternalServerException | APIKindInternalError | ApiErrorKind::InternalError |
| anything else | other | the base API error | the base API error | APIKindOther | ApiErrorKind::Other |
- The base API error is
FinlightApiError(TypeScript, Python),Finlight::ApiError(Ruby),FinlightApiException(.NET, Java, PHP),*finlight.APIError(Go) andError::Api(Rust). - Go and Rust have no subclasses. Every API error is one type; check its kind.
- The two simpler bodies above have no code. The libraries map them by status: the bad JSON body becomes
validation_failed, the unknown routenot_found. - A request that a library rejects before sending it (for example
limit: 0) raises a local validation error instead:FinlightValidationErrorin TypeScript and Python. It costs nothing. - Each library call sends its own
X-Request-Idand reuses it on every retry.
Retries in the client libraries
| Answer | What the libraries do |
|---|---|
| 400, 401, 403, 404 | Never retried. |
429 with limitType: "monthly" or an unknown limitType | Never retried. The call fails at once, also inside searchAll. |
429 with limitType: "burst" | Retried once, after exactly Retry-After seconds (10 when the header is missing). On by default. It does not count against the normal retries. |
| 5xx, gateway errors, network errors, timeouts | Up to 3 retries with growing waits, also for the search. |
You can turn off the burst retry, for example retryOnBurst: 'off' in TypeScript or retry_on_burst="off" in Python.
Handling errors in code
Generic error handler
import { FinlightClient, RateLimitedError, isFinlightApiError } from 'finlight-client'
const client = new FinlightClient({ apiKey: process.env.FINLIGHT_API_KEY! })
try {
await client.articles.search({ eventTypes: ['earnigns'] })
} catch (err) {
if (err instanceof RateLimitedError && err.limitType === 'monthly') {
console.log('Credits used up for this period')
} else if (isFinlightApiError(err)) {
console.log(err.status, err.code, err.apiKind, err.detail, err.requestId)
for (const e of err.errors) console.log(e.field, e.issue, e.allowedValues)
} else {
throw err
}
}
WebSocket errors
The WebSocket reports errors in two ways. The WebSocket pages explain each case in full.
A refused connection answers the connect request with an HTTP status. Many WebSocket libraries only show the status, not the body.
| Status | Cause | What to do |
|---|---|---|
| 401 | The key is missing or wrong. See Unauthorized. | Fix the key. Do not reconnect. |
| 403 | Your plan does not include WebSockets, you are at your connection limit, or your WebSocket quota is used up. See Forbidden. | Depends on the body. See the Forbidden page. |
| 500 | A server error. | Reconnect with backoff. |
A connection.error frame arrives on an open connection:
| Code | Connection closed? | What to do |
|---|---|---|
VALIDATION_FAILED | Yes | Fix the subscribe message. Do not reconnect with the same message. See Validation failed. |
HANDSHAKE_FAILED | Yes | Reconnect and subscribe again. |
SEARCH_FAILED | Yes | Reconnect with backoff and subscribe again. |
PING_ON_DEFAULT_ROUTE | No | Send pings as {"action":"ping","t":...}. See Lifecycle & limits. |
INTERNAL_ERROR | No | Log it. The connection stays open. |
The codes are an open list. Log unknown codes and keep the connection. See Frames for the frame format.
Webhook errors
- Setting up a webhook happens in the dashboard. It shows problems with your settings right in the form. There is no API route for this.
- Delivery failures (your endpoint did not answer with a
2xxwithin 5 seconds) are not reported back to you as an error. finlight retries them and shows each attempt in the dashboard. See Delivery & retries. - The test button is limited to 10 test sends per minute per account. After that it answers
429. See Testing.
v1 and v2 errors
The problem format is only used by v3. The v1 and v2 routes keep their old error bodies, such as {"statusCode": 429, "message": "..."}. See v2 errors.