liveBook · Manning

Fallback

As explained in Build AI-Enhanced Web Apps

A user-facing fallback is an alternative interface response or recovery option presented when the intended operation fails.

A user-facing fallback keeps an AI interface usable when generation fails, returns nothing, reaches a limit, or triggers a provider-specific restriction. It combines clear error messaging with a recovery path such as retrying the request. section 8.2.1

Implement the fallback around the server action that invokes the model. Catch the error, classify it with an error tracker, convert the result into a stable user-facing message, and render that message as an assistant response. section 8.2.1

A production-oriented fallback should:

  • Detect errors with instanceof checks or message-pattern matching. section 8.2.1
  • Centralize provider-specific error types and messages in an AIErrorTracker. section 8.2.1
  • Include a request ID so users and support workflows can identify the failed interaction. section 8.2.1
  • Offer retry when the failure is recoverable, while MCP servers can also return predefined fallback responses for unavailable external APIs. section 8.2.1 section 12.8

Chat response fallback

A conversation action catches a provider error, calls AIErrorTracker.trackError with the provider, model, and input, then renders the resulting message in a ChatBubble with an optional Retry button.

Listing 8.2 Integrating error tracking into the application
import { AIErrorTracker } from '@/lib/error-tracking';    #1
export async function continueConversation(input, provider, model) {
   ...
} catch (error) {
    const errorData = 
await AIErrorTracker.trackError(error, {    #2
      provider,
      model,
      input,
    });

    const userError = 
AIErrorTracker.createUserFacingError(errorData);    #3
    return {
      id: userError.requestId,
      role: 'assistant',
      display: (    #4
        <ChatBubble
          role="error"
          text={`${userError.message} (Request ID: ${userError.requestId})`}
          className="mr-auto border-none error"
        />
      ),
    };
  }

Inspect the complete error-handling path from caught provider exception to rendered assistant-side fallback. section 8.2.1

How Build AI-Enhanced Web Apps covers it

How deep it goes
Explains classification, centralized messaging, request IDs, rendering, and retry, but does not enumerate every provider error.
Examples
Uses AIErrorTracker, continueConversation, ChatBubble, request IDs, retry controls, and predefined MCP responses.
What it assumes
Assumes a server action that invokes an AI provider and a chat interface capable of rendering error responses.
What you can do after
Build it from scratch by catching provider errors, classifying them, rendering stable messages, and wiring recoverable cases to retry.
How it connects
Connects error handling with server actions, retry actions, AI providers, MCP servers, and frontend chat components.

Also explained in

Compare how 15 books explain fallback →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build AI-Enhanced Web Apps. The section links point to the parts of the book it draws on.