Error Handling
This guide explains how to handle errors from the SASOM Partners API.
Error Response Format
All error responses follow this format:
{
"success": false,
"message": "Error description"
}
HTTP Status Codes
| Status Code | Meaning | Description |
|---|---|---|
| 200 | OK | Request succeeded |
| 400 | Bad Request | Invalid request parameters or validation failed |
| 401 | Unauthorized | Missing or invalid authentication |
| 404 | Not Found | Resource not found or access denied |
| 429 | Too Many Requests | Rate limit exceeded |
| 500 | Internal Server Error | Server-side error |
Common Errors
Authentication Errors (401)
{
"success": false,
"message": "Invalid credentials"
}
Solutions:
- Verify your API key and secret
- Check the Authorization header format
- Ensure credentials are Base64 encoded correctly
Validation Errors (400)
Price Too Low
{
"success": false,
"message": "sku: AIR-JORDAN-1, size: 10, price: 200 - price must be at least 250 baht"
}
Solution: Ensure all prices are >= 250 baht
Duplicate SKU+Size
{
"success": false,
"message": "Duplicate SKU+size with different price: TEST-SKU**10**6000"
}
Solution: Don't include the same SKU+size combination with different prices in one request
Invalid Quantity
{
"success": false,
"message": "Quantity must be between 1 and 99"
}
Solution: Ensure quantity is 1-99
Kerry Pickup Requirements
{
"success": false,
"message": "Kerry pickup requires both pickup_date (YYYY-MM-DD) and pickup_time (HH:MM)"
}
Solution: When using logistic_type: "kerry", include both pickup_date and pickup_time
Not Found Errors (404)
{
"success": false,
"message": "Order not found or access denied"
}
Possible causes:
- Order ID doesn't exist
- Order belongs to a different supplier
- Resource was deleted
Rate Limit Errors (429)
{
"success": false,
"message": "Rate limit exceeded. Please retry after 30 seconds."
}
Solution: Wait for the Retry-After period and retry. See Rate Limiting.
Batch Operation Errors
Cannot Cancel Batch
{
"success": false,
"message": "Cannot cancel batch with status 'received'. Only 'pending' batches can be canceled."
}
Cancellation rules:
- Only
pendingbatches can be canceled - Batches with received items cannot be canceled
Error Handling Best Practices
1. Check the success Field
const response = await fetch(url, options);
const data = await response.json();
if (!data.success) {
console.error('API Error:', data.message);
// Handle error appropriately
return;
}
// Process successful response
2. Handle Specific HTTP Status Codes
async function apiRequest(url, options) {
const response = await fetch(url, options);
switch (response.status) {
case 200:
return await response.json();
case 400:
const error = await response.json();
throw new ValidationError(error.message);
case 401:
throw new AuthenticationError('Invalid credentials');
case 404:
throw new NotFoundError('Resource not found');
case 429:
const retryAfter = response.headers.get('Retry-After');
throw new RateLimitError(`Rate limited. Retry after ${retryAfter}s`);
default:
throw new Error(`Unexpected status: ${response.status}`);
}
}
3. Log Errors with Context
try {
const result = await createListing(listingData);
} catch (error) {
console.error('Failed to create listing', {
error: error.message,
sku: listingData.sku,
size: listingData.size,
timestamp: new Date().toISOString()
});
}
4. Validate Before Sending
Validate your data before making API calls to avoid unnecessary errors:
function validateListing(listing) {
const errors = [];
if (!listing.sku) errors.push('SKU is required');
if (!listing.size) errors.push('Size is required');
if (listing.price < 250) errors.push('Price must be at least 250 baht');
if (listing.quantity < 1 || listing.quantity > 99) {
errors.push('Quantity must be 1-99');
}
if (errors.length > 0) {
throw new ValidationError(errors.join(', '));
}
}
Need Help?
If you encounter persistent errors or unexpected behavior:
- Check the API Reference for correct request formats
- Review your request payload and headers
- Submit a support ticket with error details