本页面为机器翻译。英文版本为原文,可能更准确或更及时。 查看英文版

游标无效

CURSOR_INVALID 与 HTTP 400 一起返回。您发送到 POST /v3/articles/search 的 cursor 无法读取。


含义

游标是上一页中 pagination.nextCursor 的值。它是不透明的:API 只接受与其发出时完全一致的游标。这个错误表示该值不是这样的游标。它被修改过、被截断、是手工构造的,或者来自较旧的游标格式。

游标不会过期。您从 API 拿到的游标始终可以读取。

响应示例

cURL

curl -X POST 'https://api.finlight.me/v3/articles/search' \
  -H 'Content-Type: application/json' \
  -H 'X-API-KEY: YOUR_API_KEY' \
  -H 'X-Request-Id: req-123' \
  -d '{ "cursor": "not-a-cursor" }'

Response (400)

{
  "type": "https://docs.finlight.me/errors/cursor-invalid",
  "title": "Cursor invalid",
  "status": 400,
  "detail": "The cursor is not a valid base64url-encoded value.",
  "code": "CURSOR_INVALID",
  "requestId": "req-123",
  "errors": [
    { "field": "cursor", "issue": "The cursor is not a valid base64url-encoded value." }
  ]
}

常见原因

detail原因
The cursor is not a valid base64url-encoded value.该值被截断、修改或是编造的。请检查您是否原样传入了 nextCursor,例如没有多余的引号或 URL 编码。
The cursor does not carry the expected fields.该值可以解码,但不是 finlight 游标。
Unsupported cursor version '2'.该游标来自本 API 不支持的格式。

如何修正

  1. 按原样传入上一个响应中的 pagination.nextCursor。
  2. 如果您已经没有有效的游标,请不带 cursor 重新开始搜索。
  3. 当 hasMore 为 false 时停止翻页。此时 nextCursor 为 null;不要发送它。

请参阅分页。

重试

不要重试。相同的游标会再次失败。客户端库永远不会重试它,searchAll 会以这个错误停止。

在 SDK 中

语言错误
TypeScript、Python、RubyCursorInvalidError
.NET、Java、PHPCursorInvalidException
Go*finlight.APIError,其中 APIKind == finlight.APIKindCursorInvalid
RustError::Api,其中 api_kind() == ApiErrorKind::CursorInvalid

searchAll(Python:search_all)会替您处理游标,因此只有在您自己传入游标时才会出现这个错误。

捕获游标错误

import { CursorInvalidError } from 'finlight-client'

try {
  await client.articles.search({ query: 'ticker:NVDA', cursor: savedCursor })
} catch (err) {
  if (err instanceof CursorInvalidError) {
    // Start again from the first page
    await client.articles.search({ query: 'ticker:NVDA' })
  } else {
    throw err
  }
}