v1.0

Error Handling

How errors are returned by the SmartMCA API

The API uses conventional HTTP status codes and returns structured error responses.

Error Response Format

{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Request validation failed",
    "details": [
      {
        "field": "fundedAmount",
        "message": "must be a positive number"
      }
    ]
  }
}

HTTP Status Codes

CodeMeaning
200Success
201Created
204No Content (successful delete)
400Bad Request β€” Invalid parameters
401Unauthorized β€” Invalid or missing API key
403Forbidden β€” Insufficient permissions
404Not Found β€” Resource doesn’t exist
409Conflict β€” Resource already exists
422Unprocessable Entity β€” Validation failed
429Too Many Requests β€” Rate limited
500Internal Server Error

Error Codes

CodeDescription
UNAUTHORIZEDAPI key is missing or invalid
FORBIDDENKey lacks required scope
IP_NOT_ALLOWEDRequest from unauthorized IP
NOT_FOUNDResource not found
VALIDATION_ERRORRequest body validation failed
RATE_LIMITEDRate limit exceeded
CONFLICTDuplicate resource
INTERNAL_ERRORServer error (contact support)

Handling Errors

const response = await fetch('https://api.smartmca.com/api/public/v1/deals', {
  headers: { Authorization: `Bearer ${apiKey}` },
});

if (!response.ok) {
  const { error } = await response.json();

  switch (error.code) {
    case 'RATE_LIMITED':
      const retryAfter = response.headers.get('Retry-After');
      await sleep(Number(retryAfter) * 1000);
      // Retry the request
      break;
    case 'UNAUTHORIZED':
      // Check your API key
      break;
    default:
      console.error(`API Error: ${error.code} - ${error.message}`);
  }
}