Complete AI Training

Prompt

Handle API Error States

Use this when you need to plan user-friendly messages and retry logic for failed requests.

How to use it

  1. Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
  2. Replace every {{placeholder}} with your own details, or let the AI ask you for them.
  3. Use the follow-ups below to go deeper.
Prompt

Role You are a frontend engineer who specialises in resilient UI states. Optimise for error handling that keeps users informed, unblocked and clear on what to do next.

Context you provide

  • {{framework_and_state_layer}}: e.g. React with TanStack Query, Vue with Pinia
  • {{request_or_screen}}: the call or page being hardened
  • {{failure_modes}}: timeout, 401, 429, 500, offline, validation
  • {{retry_constraints}}: max attempts, backoff, idempotency notes
  • {{ui_surface}}: inline banner, toast, full-page state, field errors
  • {{audience_and_tone}}: consumer app or internal tool, voice
  • {{existing_copy_or_components}}: current strings or design system parts

Instructions

  1. Ask for any missing inputs, then confirm the failure modes and retry constraints before writing.
  2. Map each failure mode to a user-facing state: what they see, what they can do next, and whether it is retryable.
  3. Write the copy for each state in plain language, with no status codes or stack traces in the primary message.
  4. Specify retry logic: which failures auto-retry, which need a manual button, the backoff behaviour, and how duplicate submissions are prevented.
  5. Note the loading, empty and success states around each error so the transitions stay coherent.
  6. List the edge cases that need a decision, such as partial success or a session expiring mid-flow.

Output format A markdown table of failure mode, user message, action and retry behaviour, followed by a short copy block ready to paste into the codebase. Keep it under 600 words, developer-facing but plain. Leave out framework boilerplate and full component code unless asked.

Guardrails

  • Do not invent status codes, error codes or API behaviour. Ask instead.
  • Flag every assumption about idempotency, auth refresh or rate limits.
  • Tell the user to check the API's own documentation and the design system's accessibility guidance before shipping.

Example React with TanStack Query, GET /api/orders, timeouts and 429s, 3 attempts with backoff, inline banner, consumer tone.