검증 실패
VALIDATION_FAILED는 HTTP 400과 함께 옵니다. 요청의 필드나 쿼리가 유효하지 않습니다.
의미
API가 요청을 확인했고 문제를 하나 이상 찾았습니다. 아무것도 검색하지 않았습니다. errors 배열에 찾은 모든 문제가 나열되므로 한 번에 모두 고칠 수 있습니다.
각 항목에는 다음이 있습니다:
field: 요청 필드(예:eventTypes나limit). 쿼리 언어의 문제는 필드 이름badQuery를 씁니다.issue: 읽기 쉬운 텍스트. 문구는 바뀔 수 있으므로 사람에게 보여 주되 파싱하지는 마세요.allowedValues: 고정된 값 목록이 있는 필드(include,orderBy,order,roles,eventTypes,eventDirections,minImportance,sourceTypes,excludeSourceTypes)에만 있습니다.
detail은 실패한 필드 수를 알려 줍니다: 1 request field is not valid. 또는 3 request fields are not valid.
응답 예시
고정된 목록이 있는 필드의 잘못된 값:
Request
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 '{ "eventTypes": ["earnigns"] }'
Response (400)
{
"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, ipo_listing, capital_action, rating_action, management_change, legal, regulatory, bankruptcy_distress, product_partnership, investment_expansion, operational_incident, labor_restructuring, macro, geopolitics",
"allowedValues": [
"earnings", "guidance", "mna", "ipo_listing", "capital_action",
"rating_action", "management_change", "legal", "regulatory",
"bankruptcy_distress", "product_partnership", "investment_expansion",
"operational_incident", "labor_restructuring", "macro", "geopolitics"
]
}
]
}
본문 {"limit": 500, "order": "DESC"}에서 한 번에 여러 문제:
Response (400)
{
"type": "https://docs.finlight.me/errors/validation-failed",
"title": "Validation failed",
"status": 400,
"detail": "2 request fields are not valid.",
"code": "VALIDATION_FAILED",
"requestId": "req-123",
"errors": [
{ "field": "order", "issue": "order must be one of the following values: asc, desc", "allowedValues": ["asc", "desc"] },
{ "field": "limit", "issue": "limit must not be greater than 100" }
]
}
흔한 원인
| 요청 | field | issue |
|---|---|---|
목록에 없는 값, 예: "eventTypes": ["earnigns"] | eventTypes | each value in eventTypes must be one of the following values: earnings, ... |
"sourceTypes": ["wire"] | sourceTypes | each value in sourceTypes must be one of the following values: newswire, press_release, financial_media, general_media, aggregator, blog, government |
"countries": ["USA"] | countries | each value in countries must be a valid ISO31661 Alpha2 code |
"order": "DESC"(값은 소문자) | order | order must be one of the following values: asc, desc |
"limit": 0 | limit | limit must not be less than 1 |
"limit": 500 | limit | limit must not be greater than 100 |
"languages": [] | languages | languages should not be empty |
sources와 optInSources를 함께 씀 | optInSources | Can't have optInSources and sources defined simultaneously |
쿼리의 알 수 없는 필드, 예: colour:blue | badQuery | Unknown field "colour". Allowed fields: category, companyCount, ... To search for the literal text, quote it: "colour:blue". |
q도 ids도 없는 GET /v3/companies | q와 ids | Either q or ids has to be given. |
GET /v3/companies?q=NVDA&ids=1 | ids | q and ids cannot be combined. Use one of the two. |
GET /v3/companies?ids=1,abc | ids | each value in ids must not be less than 1, each value in ids must be an integer number |
GET /v3/companies/abc | companyId | companyId has to be a whole number. |
다른 쿼리 언어 문제도 필드 badQuery를 쓰고 issue에서 문제를 설명합니다. 몇몇 쿼리 검사는 요청 필드 대신 규칙 이름을 씁니다:
| 쿼리 | field | issue |
|---|---|---|
부정 용어만 있음, 예: -tesla | positiveTermRequired | Query must include at least one non-negative keyword or phrase |
| 쓸 수 있는 용어가 전혀 없음 | missingTerm | Query must include at least one valid keyword or phrase |
| 용어가 너무 많거나 중첩이 너무 깊음 | complexity | 예: Query too large (max 2000 terms) |
| 20,000자 초과 | maxLength | Query must be at most 20000 characters long |
쿼리 문법을 참조하세요.
다음 두 가지는 이 오류를 일으키지 않습니다:
- 알 수 없는 요청 필드는 오류 없이 버려집니다.
eventTypes대신eventType처럼 필드 이름의 철자가 틀리면 필터가 적용되지 않을 뿐입니다. 클라이언트 라이브러리는 보내기 전에 알 수 없는 필드를 거부합니다. - 요금제 밖의 날짜 범위는 오류 없이 요금제 범위로 잘립니다. 요금제 및 이용 권한을 참조하세요.
유효한 JSON이 아닌 요청 본문도 400을 받지만 code 없는 더 단순한 형태입니다. problem+json이 아닌 응답을 참조하세요.
해결 방법
errors[]를 읽습니다. 각 항목이 필드와 문제를 밝힙니다.allowedValues가 있는 필드는 그 값 중 하나를 고릅니다. 값은 대소문자를 구분합니다.badQuery는 필드에서 필드 이름을 확인합니다.:가 들어간 자유 텍스트는 큰따옴표로 감쌉니다.- 고친 요청을 보냅니다.
재시도
재시도하지 마세요. 같은 요청은 같은 방식으로 실패합니다. 클라이언트 라이브러리는 400을 재시도하지 않습니다.
이 검사에 실패한 요청도 기사 경로든 기업 조회든 1 크레딧이 듭니다. 속도 제한 및 크레딧을 참조하세요.
SDK에서
| 언어 | 오류 |
|---|---|
| TypeScript, Python, Ruby | ValidationFailedError |
| .NET, Java, PHP | ValidationFailedException |
| Go | APIKind == finlight.APIKindValidationFailed인 *finlight.APIError |
| Rust | api_kind() == ApiErrorKind::ValidationFailed인 Error::Api |
errors[]의 항목은 errors(필드, 문제, 허용된 값)로 사용할 수 있습니다.
일부 실수는 API까지 가지 않습니다. 라이브러리는 limit(1~100), 빈 languages, 알 수 없는 인수, 기업 조회의 q/ids 규칙을 직접 확인하고 로컬 검증 오류를 냅니다(TypeScript와 Python에서는 FinlightValidationError, Python에서 알 수 없는 인수는 TypeError). 이런 경우에는 비용이 없습니다.
검증 오류 잡기
import { ValidationFailedError } from 'finlight-client'
try {
await client.articles.search({ eventTypes: ['earnigns'] })
} catch (err) {
if (err instanceof ValidationFailedError) {
for (const e of err.errors) {
console.log(e.field, e.issue, e.allowedValues)
}
} else {
throw err
}
}
WebSocket에서
유효하지 않은 구독 메시지는 코드 VALIDATION_FAILED의 connection.error 프레임을 받습니다. 그 뒤 서버가 연결을 닫습니다. 같은 메시지로 다시 연결하지 마세요. 클라이언트 라이브러리는 검증 오류로 스트림을 끝냅니다.
WebSocket에서 문제는 details[]에 있으며 각각 field와 constraints가 있습니다:
connection.error
{
"event": "connection.error",
"payloadVersion": 3,
"data": {
"code": "VALIDATION_FAILED",
"message": "Invalid subscription message",
"details": [
{
"field": "sourceTypes",
"constraints": {
"isIn": "each value in sourceTypes must be one of the following values: newswire, press_release, financial_media, general_media, aggregator, blog, government"
},
"allowedValues": ["newswire", "press_release", "financial_media", "general_media", "aggregator", "blog", "government"]
}
]
}
}
WebSocket의 흔한 원인:
- v3 구독의 v2 키:
"payloadVersion": 3과 함께 쓴includeEntities,extended. 대신include를 쓰세요. 제약 텍스트는use include with payloadVersion 3입니다. sourceTypes,excludeSourceTypes, (보강만)include의 알 수 없는 값.- 원시 스트림의 모든
include. 원시는 기본 기사 필드만 전달합니다.