Errors

The Martis API uses conventional HTTP status codes to indicate the success or failure of requests. Codes in the 2xx range indicate success, 4xx codes indicate client errors, and 5xx codes indicate server errors.


HTTP Status Codes

CodeStatusDescription
200OKRequest succeeded
201CreatedResource created successfully
400Bad RequestInvalid request parameters or malformed request body
401UnauthorizedMissing or invalid API key
403ForbiddenValid API key but insufficient permissions
404Not FoundRequested resource does not exist
409ConflictRequest conflicts with current state (e.g., duplicate idempotency key)
422Unprocessable EntityRequest understood but cannot be processed
429Too Many RequestsRate limit exceeded
500Internal Server ErrorServer error; retry the request
502Bad GatewayUpstream service unavailable
503Service UnavailableService temporarily unavailable

Error Response Format

Error responses follow a consistent structure across all endpoints.

Client Errors (4xx)

Response 4xx

{
  "status": "fail",
  "data": {
    "field_name": ["Error message for this field"],
    "another_field": ["First error", "Second error"]
  }
}

Server Errors (5xx)

Response 5xx

{
  "status": "error",
  "message": "Internal server error"
}

Error Attributes

  • Name
    status
    Type
    string
    Description

    Error category: fail for client errors, error for server errors

  • Name
    message
    Type
    string
    Description

    Human-readable error description (primarily for 5xx errors)

  • Name
    data
    Type
    object
    Description

    Field-specific error messages (primarily for 4xx errors)


Common Error Codes

Authentication Errors

CodeMessageDescription
401Invalid or missing API keyThe Authorization header is missing or contains an invalid API key
401Wrong signatureWebhook signature verification failed
401API key expiredThe API key has been revoked or expired
403Insufficient permissionsThe API key lacks permission for the requested operation

Validation Errors

CodeMessageDescription
400payment_method is mandatoryThe payment_method field is required
400client_reference_id is mandatoryThe client_reference_id field is required
400length of client_reference_id can't > 50Reference ID exceeds 50 character limit
400Invalid Email AddressThe email address format is invalid
400length of email can't > 50Email exceeds 50 character limit
400length of phone_number can't > 50Phone number exceeds 50 character limit
400Amount must be greater than 0Payment amount must be a positive value
400Currency is requiredThe currency field is missing

Payment Errors

CodeMessageDescription
400Minimum PaymentPayment amount is below the minimum threshold
400Maximum Payment exceededPayment amount exceeds the maximum limit
404Payment channel not availableThe specified payment channel is inactive or unavailable
409Payment amount must be equal to all item priceTotal amount does not match the sum of item prices

Resource Errors

CodeMessageDescription
404Publisher not foundThe specified account_id does not exist
404Payment charge not foundThe specified charge ID does not exist
404Payout not foundThe specified payout ID does not exist
404Destination account not foundThe transfer destination account does not exist

Payout Errors

CodeMessageDescription
400Destination account is not activeThe target account for transfer is inactive
403Insufficient balance for transferSource account has insufficient funds
403Insufficient balance for payoutAccount balance is less than payout amount
400Account number is requiredBank account number is missing
400Bank code is requiredBank code identifier is missing
400Account holder name is requiredAccount holder name is missing

Idempotency Errors

CodeMessageDescription
409Idempotency key already usedThe same idempotency key was used with different parameters
409ConflictRequest conflicts with a previous request using the same idempotency key

Error Handling

Best Practices

  • Check the status code — Use the HTTP status code to determine the error category
  • Parse error messages — Extract field-specific errors from the data object for validation errors
  • Implement retries — Retry requests that fail with 5xx errors using exponential backoff
  • Log errors — Record error responses for debugging and monitoring
  • Handle gracefully — Display user-friendly messages for common errors

Retry Strategy

For transient errors (5xx codes), implement exponential backoff:

Retry with exponential backoff

async function requestWithRetry(fn, maxRetries = 3) {
  for (let attempt = 0; attempt < maxRetries; attempt++) {
    try {
      return await fn();
    } catch (error) {
      if (error.status < 500 || attempt === maxRetries - 1) {
        throw error;
      }
      const delay = Math.pow(2, attempt) * 1000;
      await new Promise(resolve => setTimeout(resolve, delay));
    }
  }
}

Validation Error Handling

Parse field-specific errors for form validation:

Parse validation errors

function handleValidationErrors(response) {
  if (response.status === 'fail' && response.data) {
    const errors = {};
    for (const [field, messages] of Object.entries(response.data)) {
      errors[field] = messages[0]; // Use first error message
    }
    return errors;
  }
  return null;
}

Debugging Tips

SymptomPossible CauseSolution
All requests return 401Invalid API keyVerify the API key is correct and not revoked
401 in production onlyEnvironment mismatchEnsure production API key is used with production URL
400 with empty dataMalformed JSONValidate request body is valid JSON
409 on retryIdempotency conflictGenerate a new idempotency key for new operations
403 after successful authFeature not enabledContact support to enable the required feature
Intermittent 5xx errorsServer issuesImplement retry logic with exponential backoff

Was this page helpful?