NueForm API पारंपरिक HTTP status codes का उपयोग करता है और structured JSON error responses लौटाता है। यह गाइड response format, सभी संभावित error codes, और अपने code में errors handle करने के patterns को कवर करती है।
Response Formats
Success Responses
सफल API calls एक data फ़ील्ड वाला JSON object लौटाती हैं। List endpoints में pagination information के साथ एक meta फ़ील्ड भी शामिल होती है।
{
"data": {
"id": "clx1abc2d3e4f5g6h7i8j9k0",
"title": "Customer Feedback",
"status": "published",
"created_at": "2026-01-15T09:30:00.000Z"
}
}
Pagination metadata के साथ:
{
"data": [
{
"id": "clx1abc2d3e4f5g6h7i8j9k0",
"title": "Customer Feedback"
},
{
"id": "clx2def3g4h5i6j7k8l9m0n1",
"title": "Employee Survey"
}
],
"meta": {
"page": 1,
"per_page": 20,
"total": 150,
"total_pages": 8
}
}
Error Responses
Error responses एक error फ़ील्ड वाला JSON object लौटाते हैं जिसमें error code, एक मानव-पठनीय message, और HTTP status code होता है।
{
"error": {
"code": "NOT_FOUND",
"message": "The requested form could not be found.",
"status": 404
}
}
Error Codes
निम्नलिखित तालिका API द्वारा लौटाए जाने वाले सभी error codes सूचीबद्ध करती है:
| Code | HTTP Status | विवरण |
|---|---|---|
BAD_REQUEST | 400 | Request गलत है, आवश्यक फ़ील्ड्स अनुपस्थित हैं, या अमान्य values हैं। |
UNAUTHORIZED | 401 | Authentication विफल। API key अनुपस्थित, गलत format, revoked, या expired है। |
FORBIDDEN | 403 | Authenticated user के पास यह कार्रवाई करने की अनुमति नहीं है। |
NOT_FOUND | 404 | अनुरोधित resource मौजूद नहीं है या authenticated user के लिए accessible नहीं है। |
CONFLICT | 409 | Request resource की वर्तमान स्थिति से conflict करता है (जैसे, duplicate entry)। |
RATE_LIMITED | 429 | बहुत अधिक requests। विवरण के लिए Rate Limits देखें। |
INTERNAL_ERROR | 500 | Server पर एक अप्रत्याशित error आया। |
Error Response उदाहरण
400 Bad Request
Request body अमान्य होने या आवश्यक फ़ील्ड्स अनुपस्थित होने पर लौटाया जाता है।
{
"error": {
"code": "BAD_REQUEST",
"message": "Field 'title' is required.",
"status": 400
}
}
401 Unauthorized
किसी भी कारण से authentication विफल होने पर लौटाया जाता है।
{
"error": {
"code": "UNAUTHORIZED",
"message": "Invalid or expired API key.",
"status": 401
}
}
403 Forbidden
User authenticated है लेकिन अनुमति नहीं है तब लौटाया जाता है। सामान्य कारणों में किसी अन्य user के resources तक पहुंचना या वर्तमान plan पर उपलब्ध न होने वाली feature का उपयोग करना शामिल है।
{
"error": {
"code": "FORBIDDEN",
"message": "API access is not available on your current plan.",
"status": 403
}
}
404 Not Found
अनुरोधित resource मौजूद न होने पर लौटाया जाता है।
{
"error": {
"code": "NOT_FOUND",
"message": "The requested form could not be found.",
"status": 404
}
}
409 Conflict
Request duplicate बनाएगा या मौजूदा data से conflict करेगा तब लौटाया जाता है।
{
"error": {
"code": "CONFLICT",
"message": "A form with this slug already exists.",
"status": 409
}
}
429 Rate Limited
Rate limit पार होने पर लौटाया जाता है। इसमें Retry-After header शामिल होता है।
{
"error": {
"code": "RATE_LIMITED",
"message": "Rate limit exceeded. Please try again later.",
"status": 429
}
}
500 Internal Error
अप्रत्याशित server error होने पर लौटाया जाता है। यदि यह बना रहता है, तो support से संपर्क करें।
{
"error": {
"code": "INTERNAL_ERROR",
"message": "An internal error occurred.",
"status": 500
}
}
Code में Errors Handle करना
JavaScript
एक पुन: प्रयोग योग्य API client बनाएं जो errors की जांच करे और typed exceptions throw करे:
class NueFormApiError extends Error {
constructor(code, message, status) {
super(message);
this.name = "NueFormApiError";
this.code = code;
this.status = status;
}
}
async function nueformRequest(path, options = {}) {
const response = await fetch(`https://app.nueform.com/api/v1${path}`, {
...options,
headers: {
"Authorization": `Bearer ${process.env.NUEFORM_API_KEY}`,
"Content-Type": "application/json",
...options.headers,
},
});
const body = await response.json();
if (!response.ok) {
const { code, message, status } = body.error;
throw new NueFormApiError(code, message, status);
}
return body;
}
// उपयोग
async function getForm(formId) {
try {
const { data } = await nueformRequest(`/forms/${formId}`);
return data;
} catch (error) {
if (error instanceof NueFormApiError) {
switch (error.code) {
case "NOT_FOUND":
console.error(`Form ${formId} does not exist.`);
return null;
case "UNAUTHORIZED":
console.error("Check your API key configuration.");
break;
case "RATE_LIMITED":
console.warn("Rate limited. Implement backoff and retry.");
break;
default:
console.error(`API error [${error.code}]: ${error.message}`);
}
}
throw error;
}
}
Python
import os
import requests
class NueFormApiError(Exception):
def __init__(self, code, message, status):
super().__init__(message)
self.code = code
self.status = status
class NueFormClient:
def __init__(self, api_key=None):
self.api_key = api_key or os.environ["NUEFORM_API_KEY"]
self.base_url = "https://app.nueform.com/api/v1"
def request(self, method, path, **kwargs):
url = f"{self.base_url}{path}"
headers = {
"Authorization": f"Bearer {self.api_key}",
"Content-Type": "application/json",
}
response = requests.request(method, url, headers=headers, **kwargs)
body = response.json()
if not response.ok:
error = body["error"]
raise NueFormApiError(
error["code"], error["message"], error["status"]
)
return body
# उपयोग
client = NueFormClient()
try:
result = client.request("GET", f"/forms/{form_id}")
form = result["data"]
print(f"Form: {form['title']}")
except NueFormApiError as e:
if e.code == "NOT_FOUND":
print(f"Form {form_id} does not exist.")
elif e.code == "UNAUTHORIZED":
print("Check your API key configuration.")
elif e.code == "RATE_LIMITED":
print("Rate limited. Implement backoff and retry.")
else:
print(f"API error [{e.code}]: {e}")
सर्वोत्तम प्रथाएं
हमेशा error फ़ील्ड की जांच करें
कभी भी केवल body की उपस्थिति के आधार पर response को सफल न मानें। Response प्रोसेस करने से पहले हमेशा error फ़ील्ड की जांच करें या HTTP status code verify करें।
Control flow के लिए विशिष्ट error codes का उपयोग करें
HTTP status code के बजाय error.code (जैसे, NOT_FOUND, RATE_LIMITED) पर match करें। Error codes स्थिर, वर्णनात्मक हैं और application logic में समझने में आसान हैं।
Error details को log करें
Debugging के लिए अपने logs में पूर्ण error response शामिल करें। code, message, और status मिलकर request को reproduce किए बिना अधिकांश समस्याओं का निदान करने के लिए पर्याप्त context प्रदान करते हैं।
5xx errors को retries के साथ handle करें
Server errors (500 Internal Error) आमतौर पर अस्थायी होते हैं। इन responses के लिए exponential backoff के साथ retry logic implement करें। विफल होने से पहले retries को 2--3 प्रयासों तक सीमित करें।
Error messages को end users को expose न करें
API error messages developers के लिए डिज़ाइन किए गए हैं, end users के लिए नहीं। अपने application में API errors को user-friendly messages में map करें।
यदि आपको लगातार 500 Internal Error responses मिल रहे हैं, तो कृपया request details और timestamps के साथ support से संपर्क करें। Server errors हमारी तरफ log होते हैं और उनकी जांच की जाती है।