beginner
5 min read
Updated: 2025-10-09
By Clipx Engineering
941 words
Support
errors
guide
cheat-sheet
notifications
ui
🚀 ERROR HANDLING - QUICK REFERENCE 🚀
"Everything you need to know in 5 minutes" ⚡
🎯 Quick Start
1. Handle API Errors
TYPESCRIPT
const response = await ApiClient.getVideoInfo(url, {
showNotifications: false // Prevent duplicate notifications
});
if (!response.success && response.details) {
setError(response.details); // Enhanced error details
showNotification.enhanced.fromErrorDetails(response.details);
}
2. Display Errors in UI
TYPESCRIPT
function ErrorDisplay({ error, onDismiss }: { error: ErrorDetails; onDismiss: () => void }) {
const [isExpanded, setIsExpanded] = useState(false);
const hasDetails = error.description || error.action;
return (
<div className={`${severityStyles[error.severity]} border rounded-xl`}>
<div onClick={hasDetails ? () => setIsExpanded(!isExpanded) : undefined}>
<div className="font-semibold">{error.title}</div>
<div className="text-sm opacity-90">{error.message}</div>
{hasDetails && <InfoIcon className="w-4 h-4" />}
</div>
{isExpanded && (
<div className="animate-in slide-in-from-top-2">
{error.description && <p>{error.description}</p>}
{error.action && <p>{error.action}</p>}
</div>
)}
</div>
);
}
🔥 Error Types Cheat Sheet
| Code | Title | Severity | Has Details |
|---|---|---|---|
SANITIZATION_FAILED | Invalid Request Content | error | ✅ |
REQUEST_ANALYSIS_FAILED | Suspicious Activity Detected | error | ✅ |
CSRF_TOKEN_INVALID | Security Token Issue | warning | ✅ |
RATE_LIMIT_EXCEEDED | Rate Limit Exceeded | warning | ✅ |
INVALID_TIKTOK_URL | Invalid TikTok URL | warning | ✅ |
NETWORK_ERROR | Network Error | error | ✅ |
NOT_FOUND | Video Not Found | warning | ✅ |
🎨 Notification Types
Standard Notifications
TYPESCRIPT
showNotification.success('Success!', 'Operation completed');
showNotification.error('Error!', 'Something went wrong');
showNotification.warning('Warning!', 'Please check your input');
showNotification.info('Info', 'Here is some information');
Enhanced Notifications
TYPESCRIPT
showNotification.enhanced.error(
'Security Token Issue',
'Your security token has expired',
'This happens when your session expires or security tokens become invalid.',
'Please wait while we refresh your security token...'
);
From ErrorDetails
TYPESCRIPT
showNotification.enhanced.fromErrorDetails(errorDetails);
🛡️ Security Error Examples
Sanitization Error
JSON
{
"success": false,
"error": "Request contains potentially harmful content",
"code": "SANITIZATION_FAILED",
"security": {
"violations": [
"Headers: Dangerous pattern detected: /<script/i",
"Headers: String length exceeds maximum (1268 > 1000)"
],
"warnings": [
"Headers: Suspicious pattern detected: /eval\(/i"
]
}
}
Result:
- Title: "Invalid Request Content"
- Description: Detailed violations list
- Action: "Please review your input, remove any suspicious content, and try again"
Request Analysis Error
JSON
{
"success": false,
"error": "Request blocked due to security concerns",
"code": "REQUEST_ANALYSIS_FAILED",
"security": {
"threatLevel": "high",
"riskScore": 85,
"reasons": [
"Suspicious user agent pattern",
"Multiple rapid requests from same IP"
]
}
}
Result:
- Title: "Suspicious Activity Detected"
- Description: "Our security system detected suspicious activity (Risk Score: 85, Threat Level: high)."
- Action: "Please ensure your request is legitimate and try again"
🚀 API Client Usage
Basic Usage
TYPESCRIPT
const response = await ApiClient.getVideoInfo(url);
if (!response.success) {
// response.details contains enhanced error information
console.log(response.details.title); // "Invalid Request Content"
console.log(response.details.description); // Detailed explanation
console.log(response.details.action); // Actionable advice
}
With Options
TYPESCRIPT
const response = await ApiClient.getVideoInfo(url, {
showNotifications: false, // Disable automatic notifications
context: 'Download Page', // Error context for debugging
maxRetries: 3 // Retry configuration
});
🎯 ErrorDetails Interface
TYPESCRIPT
interface ErrorDetails {
title: string; // User-friendly error title
message: string; // Primary error message
description?: string; // Detailed explanation
action?: string; // Actionable advice
severity: 'info' | 'warning' | 'error' | 'critical';
code: string; // Error code for debugging
}
🔧 Common Patterns
Error State Management
TYPESCRIPT
const [error, setError] = useState<ErrorDetails | null>(null);
const handleError = (errorDetails: ErrorDetails) => {
setError(errorDetails);
showNotification.enhanced.fromErrorDetails(errorDetails);
};
Error Display with Dismiss
TYPESCRIPT
<AnimatePresence>
{error && (
<ErrorDisplay
error={error}
onDismiss={() => setError(null)}
/>
)}
</AnimatePresence>
Validation Errors
TYPESCRIPT
if (!validateInput(input)) {
const errorDetails = {
title: 'Invalid Input',
message: 'Please provide valid input',
description: 'The input you provided does not meet our validation requirements.',
action: 'Please check your input and try again',
severity: 'warning' as const,
code: 'INVALID_INPUT'
};
setError(errorDetails);
showNotification.enhanced.fromErrorDetails(errorDetails);
return;
}
🎨 Styling Reference
Severity Colors
CSS
/* Critical */
.bg-red-500/10 .border-red-500/20 .text-red-600
/* Error */
.bg-destructive/10 .border-destructive/20 .text-destructive
/* Warning */
.bg-yellow-500/10 .border-yellow-500/20 .text-yellow-600
/* Info */
.bg-blue-500/10 .border-blue-500/20 .text-blue-600
Icons
TYPESCRIPT
const severityIcons = {
critical: '🚨',
error: '❌',
warning: '⚠️',
info: 'ℹ️'
};
🚀 Performance Tips
Prevent Duplicate Notifications
TYPESCRIPT
// ❌ Don't do this
const response = await ApiClient.getVideoInfo(url); // Shows notification
showNotification.error('Error', response.error); // Shows another notification
// ✅ Do this instead
const response = await ApiClient.getVideoInfo(url, {
showNotifications: false // Disable ApiClient notifications
});
if (!response.success && response.details) {
showNotification.enhanced.fromErrorDetails(response.details); // Single notification
}
Error Context
TYPESCRIPT
// Always provide context for better debugging
const response = await ApiClient.getVideoInfo(url, {
context: 'Download Page' // Helps identify where error occurred
});
🔥 Pro Tips
- Always use enhanced notifications for detailed errors
- Disable ApiClient notifications to prevent duplicates
- Provide error context for better debugging
- Use ErrorDetails interface for consistent error handling
- Implement error state management in your components
- Add error boundaries for React error handling
- Log errors for monitoring and debugging
- Test error scenarios to ensure proper handling
🎯 Quick Checklist
- Import
ErrorDetailsfrom@/lib/client/errorHandler - Use
ApiClientwithshowNotifications: false - Handle
response.detailsfor enhanced error information - Display errors with
ErrorDisplaycomponent - Use
showNotification.enhanced.fromErrorDetails() - Implement error state management
- Add error context for debugging
- Test error scenarios
That's it! You're now ready to handle errors like a PRO! 🔥🔥🔥
Built with ❤️ and TypeScript by the TikTok Downloader team
Need help? Contact support or check our troubleshooting guide.