Skip to content

Error Handling

This guide explains how to handle errors and common issues with the ParseMyFile API.

HTTP Error Codes

200 - Success

The request was processed successfully.

json
{
  "execution_time": "2.4"
  "status": "success",
  "data": {
    /* ... */
  }
}

For each error code, there is an associated message in the response

json
{
  "detail": "Message that details the error",
}

400 - Bad Request

The request contains invalid data.

401 - Unauthorized

The API key is missing or invalid.

402 - Payment Required

Insufficient credits or expired subscription

422 - Validation Error

The request parameters do not meet the expected schema.

500 - Internal Server Error

An error occurred on the server side.

Error Handling in Code

JavaScript/TypeScript

javascript
async function processDocument(file, yamlFile, apiKey) {
  try {
    const formData = new FormData();
    formData.append('file', file);
    formData.append('yaml_file', yamlFile);

    const response = await fetch('/api/v1/generate', {
      method: 'POST',
      headers: {
        'X-API-KEY': apiKey
      },
      body: formData
    });

    if (!response.ok) {
      const errorData = await response.json();
      throw new Error(`Error ${response.status}: ${errorData.message || response.statusText}`);
    }

    const result = await response.json();
    return result;
  } catch (error) {
    console.error('Error during processing:', error.message);
    throw error;
  }
}

Python

python
import requests
from requests.exceptions import RequestException

def process_document(file_path, yaml_path, api_key):
    try:
        url = "https://api.parsemyfile.com/api/v1/generate"
        headers = {"X-API-KEY": api_key}
        
        files = {
            'file': ('document.pdf', open(file_path, 'rb'), 'application/pdf'),
            'yaml_file': ('config.yaml', open(yaml_path, 'rb'), 'text/yaml')
        }
        
        response = requests.post(url, headers=headers, files=files)
        
        if response.status_code == 200:
            return response.json()
        else:
            error_data = response.json()
            raise Exception(f"Error {response.status_code}: {error_data.get('message', 'Unknown error')}")
            
    except RequestException as e:
        print(f"Request error: {e}")
        raise
    except Exception as e:
        print(f"Processing error: {e}")
        raise
    finally:
        # Close files
        if 'files' in locals():
            for file_obj in files.values():
                if hasattr(file_obj[1], 'close'):
                    file_obj[1].close()

Common Problems and Solutions

Problem: 401 Unauthorized Error

Cause: Missing or invalid API key.

Solutions:

  1. Check that the X-API-KEY header is present
  2. Verify that the API key is correct
  3. Log in to the website to get a new key
bash
# Check your API key
echo "Your API key: $API_KEY"

Problem: 402 Validation Error

Cause: Missing or invalid parameters.

Solutions:

  1. Check that both files are provided
  2. Verify file formats
  3. Check file sizes (max 10 MB)
bash
# Check files
ls -la document.pdf configuration.yaml

Problem: Low Quality Extraction

Cause: Poor document quality or inadequate configuration.

Solutions:

  1. Improve source document quality
  2. Adjust confidence threshold in YAML
  3. Enable appropriate preprocessing

Problem: 402 File Too Large

Cause: The file exceeds the limit allowed by your subscription.

Solutions:

  1. Compress the file
  2. Split the document into multiple pages
  3. Reduce image resolution

Problem: 402 Unsupported File Format

Cause: The file format is not supported or your subscription doesn't allow this file type.

Supported formats:

  • PDF
  • JPG, JPEG
  • PNG
  • DOCX
  • XLSX

Solutions:

  1. Convert the file to a supported format
  2. Use an online conversion tool
  3. Check the file extension

Support and Troubleshooting

If you encounter persistent problems:

  1. Check the logs of your application
  2. Verify the YAML configuration
  3. Test with simple files first
  4. Contact technical support with:
    • Complete error message
    • File type used
    • YAML configuration
    • Application logs

ParseMyFile API Documentation