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 the code in 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-Id header you sent. Without one, the server makes an id in the form req_<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: monthly or burst. 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

CodeHTTPWhenRetry?
VALIDATION_FAILED400A request field or the query is not valid.No. Fix the request.
CURSOR_INVALID400The cursor cannot be read.No. Start the search again without a cursor.
CURSOR_MISMATCH400The sort or the filters changed since the cursor was issued.No. Send the same body as on the first page.
UNAUTHORIZED401The API key is missing or wrong.No. Fix the key.
FORBIDDEN403Your plan does not include company data (/v3/companies).No. Upgrade your plan.
NOT_FOUND404No article or company for this id or link.No.
RATE_LIMITED429Monthly credits used up, or too many requests in 10 seconds.Burst: once, after Retry-After. Monthly: no.
INTERNAL_ERROR500Something 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 code to decide what to do. Use limitType to tell the two kinds of 429 apart.
  • Do not branch on title or detail. Their wording can change.
  • Treat an unknown code as a general error with the HTTP status. New codes can be added.
  • Log requestId with 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}:

CaseStatusBody
The request body is not valid JSON400{"message":"Unexpected end of JSON input","error":"Bad Request","statusCode":400}
The route does not exist, for example GET /v3/nope404{"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:

CodeapiKindTypeScript, Python, Ruby.NET, Java, PHPGo APIKindRust api_kind()
VALIDATION_FAILEDvalidation_failedValidationFailedErrorValidationFailedExceptionAPIKindValidationFailedApiErrorKind::ValidationFailed
CURSOR_INVALIDcursor_invalidCursorInvalidErrorCursorInvalidExceptionAPIKindCursorInvalidApiErrorKind::CursorInvalid
CURSOR_MISMATCHcursor_mismatchCursorMismatchErrorCursorMismatchExceptionAPIKindCursorMismatchApiErrorKind::CursorMismatch
UNAUTHORIZEDunauthorizedUnauthorizedErrorUnauthorizedExceptionAPIKindUnauthorizedApiErrorKind::Unauthorized
FORBIDDENforbiddenForbiddenErrorForbiddenExceptionAPIKindForbiddenApiErrorKind::Forbidden
NOT_FOUNDnot_foundNotFoundErrorNotFoundExceptionAPIKindNotFoundApiErrorKind::NotFound
RATE_LIMITEDrate_limitedRateLimitedErrorRateLimitedExceptionAPIKindRateLimitedApiErrorKind::RateLimited
INTERNAL_ERRORinternal_errorInternalServerErrorInternalServerExceptionAPIKindInternalErrorApiErrorKind::InternalError
anything elseotherthe base API errorthe base API errorAPIKindOtherApiErrorKind::Other
  • The base API error is FinlightApiError (TypeScript, Python), Finlight::ApiError (Ruby), FinlightApiException (.NET, Java, PHP), *finlight.APIError (Go) and Error::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 route not_found.
  • A request that a library rejects before sending it (for example limit: 0) raises a local validation error instead: FinlightValidationError in TypeScript and Python. It costs nothing.
  • Each library call sends its own X-Request-Id and reuses it on every retry.

Retries in the client libraries

AnswerWhat the libraries do
400, 401, 403, 404Never retried.
429 with limitType: "monthly" or an unknown limitTypeNever 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, timeoutsUp 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.

StatusCauseWhat to do
401The key is missing or wrong. See Unauthorized.Fix the key. Do not reconnect.
403Your 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.
500A server error.Reconnect with backoff.

A connection.error frame arrives on an open connection:

CodeConnection closed?What to do
VALIDATION_FAILEDYesFix the subscribe message. Do not reconnect with the same message. See Validation failed.
HANDSHAKE_FAILEDYesReconnect and subscribe again.
SEARCH_FAILEDYesReconnect with backoff and subscribe again.
PING_ON_DEFAULT_ROUTENoSend pings as {"action":"ping","t":...}. See Lifecycle & limits.
INTERNAL_ERRORNoLog 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 2xx within 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.