Error Handling

Learn how to handle errors from the FastSubmit API and troubleshoot common issues.

Response Format

All API responses follow a consistent JSON format:

Success Response

{
  "success": true,
  "data": { ... }
}

Error Response

{
  "error": "Error message",
  "errors": ["Detail 1"]
}

HTTP Status Codes

200

OK

Request successful

201

Created

Resource created successfully

400

Bad Request

Invalid request body or missing required fields

401

Unauthorized

Missing API key

403

Forbidden

Invalid API key or insufficient permissions

404

Not Found

Resource not found (form or submission)

500

Internal Server Error

Server error - please try again or contact support

Common Errors

401Missing API Key
{
  "error": "API key required. Pass via x-api-key header or apiKey query param"
}

Solution: Include your API key in the x-api-key header.

403Invalid API Key
{
  "error": "Invalid API key"
}

Solution: Verify your API key is correct. You can find it in your form's settings page.

400Validation Failed
{
  "error": "Validation failed",
  "errors": ["Email is required", "Name is required"]
}

Solution: Ensure all required fields are included. Check the errors array for details.

Best Practices

  • 1.Always check the success field in responses before processing data
  • 2.Implement retry logic with exponential backoff for 5xx errors
  • 3.Log error responses for debugging - include the full response body
  • 4.Display user-friendly error messages, not raw API errors
  • 5.Validate form data client-side before submitting to reduce errors

Example Error Handling

async function submitForm(data) {
  try {
    const response = await fetch(
      'https://fastsubmit.hostspica.com/api/submit/YOUR_FORM_ID',
      {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify(data),
      }
    );

    const result = await response.json();

    if (!response.ok) {
      switch (response.status) {
        case 400:
          console.error('Validation errors:', result.errors);
          return { success: false, message: 'Please fill in all required fields' };
        case 404:
          return { success: false, message: 'Form not found' };
        default:
          return { success: false, message: result.error || 'An error occurred' };
      }
    }

    return { success: true, message: 'Form submitted successfully!' };
  } catch (error) {
    return { success: false, message: 'Network error. Please check your connection.' };
  }
}