Sub topic 11
No results, errors, and recovery
This chapter assumes you know how filters, applied-filter chips and URL state work (covered earlier), and that you can read TypeScript and basic HTML. It covers what the interface should do when a search returns nothing or fails, and how to help users get back to results.
Four kinds of "nothing"
A blank results area can mean four different things. Each needs its own design, because the cause decides what the user can do next.
| Situation | Cause | What the user needs |
|---|---|---|
| Not started | No query or filter yet | A prompt, popular items, or recent searches |
| No results | The request worked and matched nothing | A reason and a way to change the query or filters |
| Error | The request failed | Honest wording, a retry, and their input kept |
| Loading | The response is still pending | Evidence that something is happening |
Treating these as one state is the most common mistake. An error shown as "No results found" tells the user the product does not exist when the real problem is a dropped connection.
Designing the no-results state
A good empty state does four things.
- Echoes the query. Show
No results for "bootz"so the user can spot a typo or a wrong term. - Names the likely cause. If filters are active, say so. Zero results with three filters applied usually means the filters are too narrow, not that the item is missing.
- Offers a next step. Give clickable options, not advice to "try different keywords."
- Keeps controls in place. The search field, applied-filter chips and filter panel must stay visible and editable. Clearing the interface on zero results forces the user to rebuild their work.
Recover by relaxing filters
When filters are the cause, tell the user which filter to remove and what they would get. For each active filter, count the results you would see if that filter alone were dropped. Suggest the ones that give more than zero results, largest first.
type Item = { id: string; title: string; category: string; brand: string };
type Filters = { query: string; category?: string; brand?: string };
type FilterKey = "category" | "brand";
function matches(item: Item, f: Filters, ignore?: FilterKey): boolean {
const q = f.query.trim().toLowerCase();
if (q && !item.title.toLowerCase().includes(q)) return false;
if (ignore !== "category" && f.category && item.category !== f.category) return false;
if (ignore !== "brand" && f.brand && item.brand !== f.brand) return false;
return true;
}
function relaxations(items: Item[], f: Filters) {
const keys: FilterKey[] = ["category", "brand"];
return keys
.filter((k) => Boolean(f[k]))
.map((k) => ({
key: k,
value: f[k] as string,
count: items.filter((i) => matches(i, f, k)).length,
}))
.filter((r) => r.count > 0)
.sort((a, b) => b.count - a.count);
}
const items: Item[] = [
{ id: "1", title: "Trail boots", category: "Footwear", brand: "Acme" },
{ id: "2", title: "Rain boots", category: "Footwear", brand: "Nord" },
{ id: "3", title: "Boot socks", category: "Clothing", brand: "Acme" },
];
const active: Filters = { query: "boots", category: "Clothing", brand: "Nord" };
console.log(relaxations(items, active));
// Removing "category" gives 1 result (Rain boots).
// Removing "brand" gives 1 result (Boot socks).The interface can then render buttons such as "Remove Nord (1 result)" and "Remove Clothing (1 result)". In a real app the server usually computes these counts, since the client rarely holds the full catalog. The logic is the same as facet counts, with one filter ignored at a time.
If no single removal helps, offer "Clear all filters" as the fallback. If the query itself matches nothing, move to the query-level options below.
Recover by changing the query
- Correct likely typos. If the tolerance layer finds a close match, show results for the corrected term and say so:
Showing results for "boots". Search instead for "bootz". Always let the user undo the correction. - Broaden the query. Offer the query with its last word dropped, or related terms, but only when those searches return results.
- Redirect to browsing. Link to top-level categories, popular items, or help. A dead end is worse than a weak suggestion.
- Say what is not covered. If the app only searches your own documents, say that. Users often search for something outside the scope.
Designing error states
An error means the system failed, not that the user did something wrong. The message should say what happened in plain words and what to do next. Avoid raw status codes and stack traces in the interface.
Separate the causes your design can act on:
- Offline or network failure. Say the connection failed. Keep the last results visible if you have them. Retry when the connection returns.
- Timeout. The request took too long. Offer a retry button.
- Server error (5xx). Say the problem is on your side and that retrying may work.
- Rejected input (4xx). A query that is too long, or a malformed filter value from an old shared URL. Explain the specific problem, and drop the bad parameter so the rest of the search still runs.
Three rules apply to all of them.
- Preserve input. The query text and chosen filters must survive the error.
- Preserve useful content. If earlier results exist, keep them on screen, mark them as possibly outdated, and show the error beside them. Replacing good results with an error box throws away information the user already had.
- Make retry one action. A "Try again" button reruns the same request. Retry automatically only for idempotent reads, with a limited number of attempts and a growing delay, then stop and show the button.
Model the states explicitly
Representing the state as a union type prevents the "error shown as empty" bug, because the compiler forces each case to be handled.
type Item = { id: string; title: string };
type SearchState =
| { status: "loading" }
| { status: "results"; items: Item[] }
| { status: "empty"; query: string }
| { status: "error"; kind: "offline" | "timeout" | "server" | "rejected"; retryable: boolean };
async function runSearch(
url: string,
query: string,
userSignal: AbortSignal,
timeoutMs = 5000
): Promise<SearchState | "cancelled"> {
const timeout = AbortSignal.timeout(timeoutMs);
const signal = AbortSignal.any([userSignal, timeout]);
try {
const res = await fetch(url, { signal });
if (res.status >= 500) return { status: "error", kind: "server", retryable: true };
if (!res.ok) return { status: "error", kind: "rejected", retryable: false };
const data = (await res.json()) as { items: Item[] };
return data.items.length === 0
? { status: "empty", query }
: { status: "results", items: data.items };
} catch {
if (userSignal.aborted) return "cancelled";
if (timeout.aborted) return { status: "error", kind: "timeout", retryable: true };
return { status: "error", kind: "offline", retryable: true };
}
}The "cancelled" result matters. When the user types again, you abort the previous request. That abort is not a failure and must never produce an error message.
Edge cases
- Stale responses. If a slow response for "boo" arrives after the response for "boots", it can overwrite the newer results. Abort the older request, or ignore any response whose request id is not the latest.
- Disabled options. Greying out filter values with a zero count prevents many empty states before they happen. Keep them focusable and explain why they are unavailable, rather than hiding them, so users keep a stable layout.
- Empty browse versus empty search. A category with no items needs different copy than a failed query. "Nothing here yet" fits a new folder. It does not fit a search.
- Partial failure. If suggestions fail but results load, show the results. Do not block the whole page for a secondary feature.
- Old shared URLs. A link with a removed category value should load without that parameter and tell the user it was dropped.
- Permission limits. If the user cannot see some matches, a vague "no results" can mislead. Say that results are limited to what they can access.
Announcing states to assistive technology
Screen reader users get no visual cue when the results area changes, so announce each state. Use role="status" for the count and empty message, which is polite and waits for the user to pause. Use role="alert" only for errors that block the task, since it interrupts. Keep these elements in the page from the start, because live regions announce reliably only when their content changes after they exist.
<div id="results-region">
<p role="status" id="result-status">No results for "bootz" with 2 filters applied.</p>
<ul id="recovery">
<li><button type="button">Remove brand: Nord (1 result)</button></li>
<li><button type="button">Clear all filters</button></li>
</ul>
</div>
<div role="alert" id="search-error" hidden>
Search is not responding. Your filters are saved.
<button type="button">Try again</button>
</div>After the user activates a recovery action, move focus predictably, usually to the results heading, so keyboard users are not left on a button that has disappeared.
Common mistakes
- Returning an empty list on failure and rendering the no-results message.
- Clearing filters and the query when a request fails.
- Writing copy like "Oops! Something went wrong" with no cause or next step.
- Auto-retrying in a tight loop, which adds load during an outage.
- Offering recovery links that lead to more empty pages.
Exercise
A user searches "rain jacket" with filters Size: XS and Color: Yellow, and the API returns 200 with {"items": []}. Removing Size alone gives 6 results. Removing Color alone gives 0. Removing both gives 40. What should the page show, and which state is it?
Show answer
This is the no-results state, not an error, because the request succeeded. Echo the query and name the active filters. Offer "Remove Size: XS (6 results)" as the primary suggestion. Do not offer a Color removal on its own, since it still returns nothing. Add "Clear all filters (40 results)" as the fallback. Keep the search field and filter panel visible and announce the message through a role="status" region.
Exercise
Your search request times out after 5 seconds while the user already sees results from the previous query. Describe the design of the error state and the state type it maps to.
Show answer
It maps to { status: "error", kind: "timeout", retryable: true }. Keep the previous results on screen, mark them as possibly outdated, and show a message that the search took too long next to a "Try again" button. Keep the new query text and all filters. Use role="alert" if the message blocks the task, and do not show the empty state.