api-error-handling

Apply unified API error handling to Alova useRequest calls in uniapp Vue3 projects.

Updated Sep 11, 2025
One-click install
npx skills add https://github.com/ruan-cat/11comm-app --skill api-error-handling-ruan-cat
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: api-error-handling
Source: https://github.com/ruan-cat/11comm-app/tree/main/.claude/skills/api-error-handling
Command: npx skills add https://github.com/ruan-cat/11comm-app --skill api-error-handling-ruan-cat

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

The skill standardizes API error messaging and handling across the frontend so developers avoid duplicated error UI, incorrect try/catch patterns, and inconsistent user feedback while ensuring clear severity-based responses.

Core Features & Use Cases

  • Global interception: maps HTTP and business codes to user-friendly messages and severity levels via the responded interceptor.
  • Component callbacks: enforces the use of useRequest with immediate: false and onError/onSuccess callbacks for business recovery and state restoration.
  • Error classification: defines fatal, severe, normal, and light levels with matched UI actions (modal, toast, warning, silent).
  • Use cases: list queries, form submissions, paginated loads, silent requests that disable automatic toasts, and migration from legacy API patterns.

Quick Start

Apply the project's API error handling rules to this component's useRequest calls to ensure immediate:false, proper onError handling, and no try/catch wrapping of send().

Frequently Asked Questions about api-error-handling

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle API errors consistently in uniapp Vue3 with Alova?

To handle API errors consistently in uniapp Vue3, use a global interceptor in src/http/alova.ts to map HTTP and business codes to user-friendly messages and severity levels. This prevents duplicated error UI and incorrect try/catch patterns across components.

How do I classify API error severity levels for different UI feedback?

API error severity is classified into fatal, severe, normal, and light levels. Each level maps to matched UI actions like modal, toast, warning, or silent, ensuring users receive appropriate feedback based on the error's impact.

Do I need to use try/catch with Alova useRequest send() for error handling?

No, you should not wrap useRequest send() in try/catch. Instead, enforce immediate:false and use onError callbacks for business recovery and state restoration, letting the global interceptor handle the actual error messaging.

Can I disable automatic error toasts for silent API requests in Alova?

Yes, silent requests can disable automatic toasts by leveraging the error classification system. By mapping specific errors to the light severity level, the request processes silently without triggering standard UI warnings.

What is the best way to standardize form submission error handling across frontend components?

The best way to standardize form submission error handling is enforcing useRequest with onError callbacks alongside a global responded interceptor. This ensures consistent severity mapping and user feedback without duplicated error UI logic.

Why does my useRequest onError callback not trigger in Alova?

Your useRequest onError callback may not trigger if immediate is not set to false or if send() is wrapped in try/catch. Ensure immediate:false is enforced and rely on the interceptor for error mapping.