Skip to content

Errors

The Fyber API uses standard HTTP status codes and returns detailed error information.

HTTP Status Codes

CodeDescription
200Success
400Bad Request - Invalid parameters
401Unauthorized - Invalid API key
402Payment Required - Card declined
404Not Found - Resource doesn't exist
429Too Many Requests - Rate limited
500Server Error - Something went wrong

Error Response

json
{
  "error": {
    "type": "card_error",
    "code": "card_declined",
    "message": "Your card was declined.",
    "param": null
  }
}
FieldDescription
typeError category
codeSpecific error code
messageHuman-readable message
paramParameter that caused the error (if applicable)

Error Types

api_error

Server-side error. Retry the request or contact support.

authentication_error

Invalid API key. Check your credentials.

card_error

Card was declined. Display the message to the customer.

invalid_request_error

Invalid request parameters. Check the param field.

rate_limit_error

Too many requests. Wait before retrying.

validation_error

Request validation failed. Check required fields.

Error Codes

Card Errors

CodeDescription
card_declinedCard was declined
expired_cardCard has expired
incorrect_cvcCVC is incorrect
incorrect_numberCard number is incorrect
insufficient_fundsInsufficient funds
processing_errorProcessing error

Request Errors

CodeDescription
missing_required_paramRequired parameter missing
invalid_paramParameter value is invalid
resource_not_foundResource doesn't exist
resource_already_existsResource already exists

Authentication Errors

CodeDescription
invalid_api_keyAPI key is invalid
api_key_expiredAPI key has expired

Handling Errors

JavaScript

javascript
try {
  const payment = await fyber.payments.create({...});
} catch (error) {
  switch (error.type) {
    case 'card_error':
      // Display error.message to customer
      console.log('Card error:', error.message);
      break;
    case 'validation_error':
      // Fix the request parameters
      console.log('Validation error:', error.message, error.param);
      break;
    case 'authentication_error':
      // Check API key
      console.log('Auth error - check API key');
      break;
    case 'rate_limit_error':
      // Wait and retry
      await sleep(error.retryAfter * 1000);
      break;
    default:
      // Log and investigate
      console.error('Unexpected error:', error);
  }
}

PHP

php
try {
    $payment = $fyber->payments->create([...]);
} catch (FyberException $e) {
    switch ($e->getType()) {
        case 'card_error':
            echo "Card error: " . $e->getMessage();
            break;
        case 'validation_error':
            echo "Validation error: " . $e->getMessage();
            break;
        case 'authentication_error':
            echo "Check your API key";
            break;
        default:
            echo "Error: " . $e->getMessage();
    }
}

C#

csharp
try
{
    var payment = await fyber.Payments.CreateAsync(request);
}
catch (FyberException ex)
{
    switch (ex.Type)
    {
        case "card_error":
            Console.WriteLine($"Card error: {ex.Message}");
            break;
        case "validation_error":
            Console.WriteLine($"Validation error: {ex.Message}");
            break;
        case "authentication_error":
            Console.WriteLine("Check your API key");
            break;
        default:
            Console.WriteLine($"Error: {ex.Message}");
            break;
    }
}

Flutter

dart
try {
  final payment = await fyber.payments.create(...);
} on FyberException catch (e) {
  if (e.isCardError) {
    print('Card error: ${e.message}');
  } else if (e.isValidationError) {
    print('Validation error: ${e.message}');
  } else if (e.isAuthError) {
    print('Check your API key');
  } else {
    print('Error: ${e.message}');
  }
}

Customer-Facing Messages

For card errors, display the message field to customers. These messages are designed to be user-friendly:

  • "Your card was declined."
  • "Your card has expired."
  • "Your card's security code is incorrect."
  • "Insufficient funds."

For other errors, display a generic message and log the details for debugging.

Fyber Payment API