वैलिडेशन विफल
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 | *finlight.APIError जिसमें APIKind == finlight.APIKindValidationFailed |
| Rust | Error::Api जिसमें api_kind() == ApiErrorKind::ValidationFailed |
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 पर
जो subscribe संदेश मान्य नहीं है, उसे 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 subscribe में v2 की कुंजी:
"payloadVersion": 3के साथincludeEntitiesयाextended। इनकी जगहincludeइस्तेमाल करें। constraint टेक्स्ट हैuse include with payloadVersion 3। sourceTypes,excludeSourceTypesया (केवल एनरिच्ड में)includeमें अज्ञात मान।- रॉ स्ट्रीम पर कोई भी
include। रॉ केवल लेख के बुनियादी फ़ील्ड डिलीवर करता है।
सब्सक्राइब करें और रॉ स्ट्रीम देखें।