Sub topic 11
No results, errors, and recovery
Assume you understand forms, lists, URL query parameters, and basic TypeScript. This chapter focuses on how a search interface responds when it cannot show useful results.
A search result can fail for different reasons. The query may be valid but match nothing. The server may be unavailable. A filter combination may be too narrow. Treating all these cases as “no results” hides the real problem and gives users the wrong recovery action.
Distinguish empty, error, and loading states
Use the state that matches what happened:
| State | Meaning | Useful user action |
|---|---|---|
| No results | The request succeeded, but nothing matched | Change the query or remove filters |
| Error | The request did not complete successfully | Retry or check connectivity |
| Loading | A request is still running | Wait or cancel the request |
| Partial results | Some data loaded, but another part failed | Continue with available data or retry the failed part |
An empty state should confirm the search and filters that produced it. For example, “No products match boots in size 12” is more useful than “Nothing found.”
Keep the user's input and applied filters visible. Do not silently clear them. Users need to know what caused the empty state and what they can change.
type SearchState =
| { kind: "loading"; query: string }
| { kind: "success"; query: string; total: number }
| { kind: "empty"; query: string; activeFilters: string[] }
| { kind: "error"; query: string; activeFilters: string[]; message: string };
function recoveryActions(state: SearchState): string[] {
switch (state.kind) {
case "empty":
return state.activeFilters.length > 0
? ["Clear filters", "Edit search"]
: ["Check spelling", "Try a broader search"];
case "error":
return ["Retry", "Keep current search"];
default:
return [];
}
}Design useful empty states
Offer recovery actions that match the likely cause:
- Show spelling or synonym suggestions when the query may be too specific.
- Provide a “Clear all filters” action when filters caused the empty result.
- Suggest broader categories, popular searches, or recently viewed items when appropriate.
- Explain when the catalog itself has no matching content.
- Keep the search field focused only when that helps users continue typing.
Avoid inventing results that do not match the request. A “close match” section should be labeled clearly and should not replace the exact-results state.
A reset action should have a predictable scope. “Clear filters” should preserve the query. “Clear search” should preserve unrelated filters only if that behavior is obvious from the interface.
Recover from errors
An error means the system could not determine the result. Do not display “No results” after a timeout or server failure. That message can make users believe their query was wrong.
Show:
- What failed, in plain language.
- A retry action.
- Whether the current query and filters remain intact.
- Any content that loaded successfully.
- A support or status link when the failure is persistent.
Retrying should reuse the same request state. If the user changes the query, cancel or ignore the older request so a late response cannot overwrite newer results.
Make recovery visible
A simple state flow helps keep transitions consistent.
Preserve state during recovery. When users return from a detail page, use the browser back button, or retry a request, restore the query, filters, sort order, and result position when possible.
Test recovery behavior
Test more than the visual message. Verify that actions preserve or change exactly the state they claim to change.
Exercise
A user searches for “camera” and selects “Used,” but no items match. What should “Clear filters” do?
Show answer
It should remove the “Used” filter, preserve the “camera” query, and run or enable a new search that can show unfiltered results.