ResourcesError Handling
Resources

Error Handling

Understanding and handling Flameup API errors

Error Response Format

Flameup API errors use the following format:

{
  "success": false,
  "error": {
    "type": "ERROR_TYPE",
    "message": "Human-readable error message"
  },
  "request_id": "req_abc123"
}
Some endpoints may return a simplified format: {"error": "message", "message": "details"}. Check the specific endpoint documentation.

HTTP Status Codes

Flameup uses standard HTTP status codes:

CodeMeaningDescription
200OKRequest succeeded
201CreatedResource created successfully
204No ContentRequest succeeded (no response body)
400Bad RequestInvalid request parameters
401UnauthorizedMissing or invalid API key
403ForbiddenInsufficient permissions
404Not FoundResource doesn't exist
409ConflictResource already exists
422Unprocessable EntityValidation failed
429Too Many RequestsRate limit exceeded
500Internal Server ErrorServer-side error
503Service UnavailableTemporary unavailability

Common Error Codes

Authentication Errors

HTTP Status: 401

API key is missing or invalid.

{
  "error": {
    "code": "unauthorized",
    "message": "Invalid or missing API key"
  }
}

Solutions:

  • Verify the API key is correct
  • Check the Authorization header is set with Bearer prefix
  • Ensure the key hasn't been revoked

Resource Errors

HTTP Status: 404

The requested resource doesn't exist.

{
  "error": {
    "code": "not_found",
    "message": "Person with ID 'xyz' not found"
  }
}

Solutions:

  • Verify the resource ID is correct
  • Check you're using the right workspace

Validation Errors

HTTP Status: 422

Request body failed validation.

{
  "error": {
    "code": "validation_error",
    "message": "Validation failed",
    "details": {
      "fields": {
        "email": "Invalid email format",
        "userId": "Required field"
      }
    }
  }
}

Solutions:

  • Check the request body matches the API spec
  • Validate data before sending

Rate Limiting Errors

HTTP Status: 429

Too many requests in a time window.

{
  "error": "Rate limit exceeded",
  "message": "Too many requests. Please try again later."
}

Solutions:

  • Check the X-RateLimit-Reset header for when to retry
  • Implement exponential backoff
  • Consider upgrading your plan for higher limits

Error Handling Best Practices

Retry Strategy

Implement exponential backoff for transient errors:

async function fetchWithRetry(url, options, maxRetries = 3) {
  for (let attempt = 0; attempt < maxRetries; attempt++) {
    try {
      const response = await fetch(url, options);

      if (response.ok) {
        return response.json();
      }

      const error = await response.json();

      // Don't retry client errors (except rate limits)
      if (response.status >= 400 && response.status < 500) {
        if (response.status === 429) {
          // Rate limited - wait and retry using header
          const resetTime = parseInt(response.headers.get('X-RateLimit-Reset') || '0') * 1000;
          const waitTime = resetTime > Date.now() ? resetTime - Date.now() : 60000;
          await sleep(waitTime);
          continue;
        }
        throw new FlameupError(error);
      }

      // Server error - retry with backoff
      if (attempt < maxRetries - 1) {
        await sleep(Math.pow(2, attempt) * 1000);
        continue;
      }

      throw new FlameupError(error);

    } catch (networkError) {
      if (attempt < maxRetries - 1) {
        await sleep(Math.pow(2, attempt) * 1000);
        continue;
      }
      throw networkError;
    }
  }
}

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

Error Logging

Log errors with context for debugging:

function logError(error, context) {
  console.error('Flameup API Error', {
    code: error.code,
    message: error.message,
    details: error.details,
    context: {
      endpoint: context.endpoint,
      method: context.method,
      userId: context.userId,
      timestamp: new Date().toISOString()
    }
  });
}

User-Friendly Messages

Map error codes to user-friendly messages:

const ERROR_MESSAGES = {
  unauthorized: 'Please check your API credentials',
  forbidden: 'You don\'t have permission for this action',
  not_found: 'The requested item was not found',
  validation_error: 'Please check your input and try again',
  rate_limit_exceeded: 'Too many requests. Please wait a moment.',
  default: 'Something went wrong. Please try again.'
};

function getUserMessage(errorCode) {
  return ERROR_MESSAGES[errorCode] || ERROR_MESSAGES.default;
}

Debugging Tips

Use these tips to debug API issues:
  1. Check the response body - Error details are always in the response
  2. Verify API key permissions - Most 403 errors are permission issues
  3. Validate request format - Use the API reference for correct schemas
  4. Check rate limit headers - Monitor X-RateLimit-* headers
  5. Use test environment - Debug in test before going to production
Was this page helpful?
Built with Documentation.AI

Last updated today