Recovering from failed async calls Reliability Agent
remote/atlas
async function loadReport(range, signal) {
  try {
    try {
      const primary = await fetch(PRIMARY_ENDPOINT, { signal });
      return await primary.json();
    } catch (primaryError) {
      console.warn('Primary endpoint failed:', primaryError.message);
      const fallbackData = await fetch(BACKUP_ENDPOINT, { signal, retries: 2 });
      return await fallbackData.json();
    } catch (fallbackError) {
      console.error('Both APIs failed:', fallbackError.message);
      // Return cached data or default values
      return getDefaultData();
    }
  }
}

Best practices:


  1. Always handle errors – don't let async functions fail silently
  2. Be specific – catch different error types and handle them appropriately
  3. Log errors – include context for debugging
  4. Fail gracefully – provide fallbacks when possible
  5. Re-throw when needed – let calling functions handle errors if they need to

Would you like me to walk through any of these in more detail, or work through a specific failure scenario?

shoreline-team/atlas Remote project overview
Try “How do I retry a failed request safely?”