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
| Code | Status | Description |
|---|---|---|
200 | OK | Request succeeded |
201 | Created | Resource created successfully |
400 | Bad Request | Invalid request parameters or malformed request body |
401 | Unauthorized | Missing or invalid API key |
403 | Forbidden | Valid API key but insufficient permissions |
404 | Not Found | Requested resource does not exist |
409 | Conflict | Request conflicts with current state (e.g., duplicate idempotency key) |
422 | Unprocessable Entity | Request understood but cannot be processed |
429 | Too Many Requests | Rate limit exceeded |
500 | Internal Server Error | Server error; retry the request |
502 | Bad Gateway | Upstream service unavailable |
503 | Service Unavailable | Service 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:
failfor client errors,errorfor 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
| Code | Message | Description |
|---|---|---|
401 | Invalid or missing API key | The Authorization header is missing or contains an invalid API key |
401 | Wrong signature | Webhook signature verification failed |
401 | API key expired | The API key has been revoked or expired |
403 | Insufficient permissions | The API key lacks permission for the requested operation |
Validation Errors
| Code | Message | Description |
|---|---|---|
400 | payment_method is mandatory | The payment_method field is required |
400 | client_reference_id is mandatory | The client_reference_id field is required |
400 | length of client_reference_id can't > 50 | Reference ID exceeds 50 character limit |
400 | Invalid Email Address | The email address format is invalid |
400 | length of email can't > 50 | Email exceeds 50 character limit |
400 | length of phone_number can't > 50 | Phone number exceeds 50 character limit |
400 | Amount must be greater than 0 | Payment amount must be a positive value |
400 | Currency is required | The currency field is missing |
Payment Errors
| Code | Message | Description |
|---|---|---|
400 | Minimum Payment | Payment amount is below the minimum threshold |
400 | Maximum Payment exceeded | Payment amount exceeds the maximum limit |
404 | Payment channel not available | The specified payment channel is inactive or unavailable |
409 | Payment amount must be equal to all item price | Total amount does not match the sum of item prices |
Resource Errors
| Code | Message | Description |
|---|---|---|
404 | Publisher not found | The specified account_id does not exist |
404 | Payment charge not found | The specified charge ID does not exist |
404 | Payout not found | The specified payout ID does not exist |
404 | Destination account not found | The transfer destination account does not exist |
Payout Errors
| Code | Message | Description |
|---|---|---|
400 | Destination account is not active | The target account for transfer is inactive |
403 | Insufficient balance for transfer | Source account has insufficient funds |
403 | Insufficient balance for payout | Account balance is less than payout amount |
400 | Account number is required | Bank account number is missing |
400 | Bank code is required | Bank code identifier is missing |
400 | Account holder name is required | Account holder name is missing |
Idempotency Errors
| Code | Message | Description |
|---|---|---|
409 | Idempotency key already used | The same idempotency key was used with different parameters |
409 | Conflict | Request 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
dataobject for validation errors - Implement retries — Retry requests that fail with
5xxerrors 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
| Symptom | Possible Cause | Solution |
|---|---|---|
All requests return 401 | Invalid API key | Verify the API key is correct and not revoked |
401 in production only | Environment mismatch | Ensure production API key is used with production URL |
400 with empty data | Malformed JSON | Validate request body is valid JSON |
409 on retry | Idempotency conflict | Generate a new idempotency key for new operations |
403 after successful auth | Feature not enabled | Contact support to enable the required feature |
Intermittent 5xx errors | Server issues | Implement retry logic with exponential backoff |
Before contacting support, verify the request format and parameters. Most errors result from incorrect request construction or missing required fields.