Error Handling

Parsewise API uses standard HTTP status codes to indicate request success or failure. All errors are returned in a unified JSON format.

Error Format

All errors are returned in JSON format with field detail:

{
  "detail": "Error description in English"
}

HTTP Status Codes

CodeNameDescription
200OKRequest successful
201CreatedResource successfully created
204No ContentSuccessful deletion (no response body)
400Bad RequestInvalid request parameters
401UnauthorizedMissing or invalid token
403ForbiddenInsufficient permissions
404Not FoundResource not found
429Too Many RequestsRate limit exceeded
500Internal Server ErrorServer error

Error Examples

400 Bad Request

Invalid request parameters:
{
  "detail": "message: field required"
}

401 Unauthorized

Authentication issues:
{
  "detail": "Invalid authorization header format. Use: Bearer <token>"
}
{
  "detail": "Invalid API token"
}

403 Forbidden

Insufficient permissions:
{
  "detail": "This endpoint requires EDITOR role or higher"
}

404 Not Found

Resource not found:
{
  "detail": "Product not found"
}
{
  "detail": "Chat not found"
}

429 Too Many Requests

Rate limit exceeded:
{
  "detail": "Rate limit exceeded. Try again in 60 seconds."
}

Rate Limits

Request TypeLimit
Standard requests100 per minute
SSE connections10 concurrent
Bulk operations10 per minute

When the limit is exceeded, you'll get a 429 Too Many Requests.

Error Handling in Code

import requests

def make_api_request(endpoint, method="GET", data=None):
    headers = {"Authorization": "Bearer pw_your_token"}
    url = f"https://api.parsewise.ru/v1{endpoint}"
    
    try:
        response = requests.request(method, url, headers=headers, json=data)
        response.raise_for_status()
        return response.json()
    except requests.exceptions.HTTPError as e:
        if e.response.status_code == 401:
            print("Authentication error. Check your token.")
        elif e.response.status_code == 403:
            print("Insufficient permissions. Use Editor token.")
        elif e.response.status_code == 404:
            print("Resource not found.")
        elif e.response.status_code == 429:
            print("Too many requests. Please wait.")
        else:
            print(f"Error: {e.response.json().get('detail', 'Unknown error')}")
        return None

Retry with Exponential Backoff

For 429 and 5xx errors, we recommend retrying requests with increasing delay:

import time
import random

def request_with_retry(url, max_retries=3):
    for attempt in range(max_retries):
        response = requests.get(url, headers=headers)
        
        if response.status_code == 200:
            return response.json()
        
        if response.status_code in [429, 500, 502, 503, 504]:
            delay = (2 ** attempt) + random.uniform(0, 1)
            print(f"Retry {attempt + 1}/{max_retries} in {delay:.1f}s")
            time.sleep(delay)
        else:
            response.raise_for_status()
    
    raise Exception("Max retries exceeded")

Was this page helpful?