Why an API Outage Replaced the Home Page With an Empty List: catch { return [] }
Pages had stayed up with the API stopped in Part 5, and I had added explicit cache clearing in Part 6. For almost two months, the setup seemed fine.
An August code review uncovered another path. If the cache regenerated while the API was down, the home page could turn into "No posts yet." The API client was returning an empty list on connection failures.
Six functions returning empty lists
During a full quality review, I read the web app's API client file. Six functions that fetched posts, categories, tags, and so on all looked like this:
export async function getPosts(): Promise<PostSummary[]> { try { const res = await fetch(`${base}/api/posts`, { next: { revalidate: 60, tags: ["blog-content"] } }); if (!res.ok) return []; return (await res.json()) as PostSummary[]; } catch { return []; }}The code was meant to keep the page working when the API failed. Returning an empty list, however, left the caller unable to distinguish an empty blog from a failed lookup.
The problem was where that empty list ended up.
The path this check needed to cover
Beyond the cache-hit check in Part 5, this reproduction tested API failure while an expired page was being regenerated. Serving a cached response and handling regeneration failure are separate paths.
Stopping the mock API and checking every 15 seconds
I set up a mock API and a web server started from real next build output, filled the cache with normal content, and then stopped the API. I checked the home page, sitemap, and RSS every 15 seconds.
| After the API stopped | Home | Sitemap URLs | RSS items |
|---|---|---|---|
| 0 s | Normal | 10 | 1 |
| 15 s | Normal | 10 | 1 |
| 30 s | "No posts yet" | 10 | 1 |
| 45 s | "No posts yet" | 4 | 0 |
| 60 s and later | Still empty | Still 4 | Still 0 |
Bringing the API back didn't fix it right away. The empty pages stayed until the next revalidation window. The 4 sitemap URLs were only fixed pages unrelated to posts.
Zero in this table is the API shutdown time. The cache was populated earlier, so "30 seconds after shutdown" and "60 seconds after cache creation" are different clocks. The table does not record exact cache creation times per route, and these measurements alone do not explain the differences in refresh timing.
The cause: turning a failure into a success
Next.js continues serving the last successful result if background page regeneration throws an error. [S1] This reproduction already had a good page in the cache, so that result should have remained available.
But that safety net only works when a failure is reported as a failure.
Preparing diagram.
Diagram source
flowchart TB
R[Request after expiry / regenerate] --> F[API connection fails]
F -->|Throw error| K[Regeneration fails / keep old page]
F -->|Return empty list| S[Empty page renders successfully]
S --> E[Replace page cache with empty output]catch { return [] } turned "I couldn't fetch it right now" into "there is no content." The page rendered that value without an error, and the empty output replaced the good page. The cache being replaced here was the Full Route Cache, which stores rendered page output. This does not mean the application's fallback [] was itself stored in the fetch Data Cache.
Missing posts and server outages were mixed up too
The function that fetched a single post had the same problem. if (!res.ok) return null converted HTTP responses such as 404 and 500 to null; a separate catch converted connection failures to null too. So when the API stopped, posts that really existed returned 404.
What a crawler receives during the outage
Serving the empty page with 200 also gives crawlers misleading content. Google considers 200 responses for indexing without guaranteeing inclusion, and may classify an empty page as a soft 404. For 5xx responses, it ignores the content and reduces crawling. Existing index entries are initially retained, but persistent server errors can lead to removal. [S2]
The sitemap also lost real post URLs. That alone does not establish that posts would immediately disappear from search results. What I could see was a list the app had failed to fetch being served as if it were a valid list.
How I fixed it
1. Throw failures, and treat only 404 as "not found"
I created a dedicated error type for failures and split list fetches from single-item fetches.
export class BlogApiError extends Error { /* ... */ }async function get<T>(path: string, options?: RequestInit): Promise<T> { const res = await request(path, options); if (!res.ok) throw new BlogApiError(path, res.status); return (await res.json()) as T;}// Only 404 means "not found"; throw other failures. (Comment translated.)async function getOrNull<T>(path: string): Promise<T | null> { const res = await request(path); if (res.status === 404) return null; if (!res.ok) throw new BlogApiError(path, res.status); return (await res.json()) as T;}The request helper above also wraps connection failures in BlogApiError and throws them. For the main content fetches at runtime, an empty list now comes from a successful API response. When regeneration errors reach Next.js, the last good page is kept. Build-time and secondary-list exceptions are covered below.
2. Add an error screen for pages without a cache
A failed API lookup now raises an error when the page has no cached result. I added Korean and English error.tsx screens with a message and retry button inside the site's header and footer. The uncached routes checked at the time returned HTTP 500.
An error.tsx screen does not itself guarantee 500. If a streaming response has already sent 200 headers, a later error cannot change that status. The error screen and HTTP status need separate checks. [S3]
3. Wait for the API port before starting the web app
The compose file's depends_on: [blog-api] only waited for the API container to start. During the ten-plus seconds Spring Boot took to boot, the web app was already taking requests. I added a health check to the API and set the web app's dependency to condition: service_healthy so it would wait for that check. [S4]
healthcheck: test: ["CMD", "bash", "-c", "echo > /dev/tcp/127.0.0.1/8080"]There's no guarantee that curl or wget exists in the image, so it uses bash's /dev/tcp to check only that the port accepts connections. This checks TCP connectivity only; it does not guarantee that an API request or database query will succeed. If this command were wrong, the web app would never start, so before deploying to production I separately confirmed that the health check actually passed.
Then the build broke
As soon as I made failures throw, next build failed, because the build environment has no API. While fixing that, I discovered that every deployment had been baking "a blog with no posts at all" into the image. That story gets its own post next.
Verification
In the reproduction environment (mock API and real build output), I compared before and after the fix.
| Situation | Before the fix | After the fix |
|---|---|---|
| API stopped for 100 s | Home empty, sitemap 4, RSS 0 | Home normal, sitemap 10, RSS 1 kept |
| Page with no cache + outage | 200 (empty list) or 404 | 500 + message screen |
| Detail request checked after API recovery | Recovered immediately in the reproduction | Recovered immediately |
| A post that truly doesn't exist | 404 | Still 404 |
After deploying to the production Mac the next day, I ran the same checks. Across four checks during a 90-second API stop, the home page stayed at 200 with zero empty screens, and the sitemap's 18 URLs and the RSS feed's 1 item stayed the same. During the outage, a path with no cache returned 500, not 404, and once the API came back it returned 200 right away.
Exceptions I kept on purpose
Not everything throws. Two features I built later deliberately swallow failures:
- On a post page, the "related posts" and "previous/next post" lists become empty on failure. Whether the page exists is decided by the fetch for the post itself, and these lists are secondary.
- On the 404 page, the "recent posts" section simply disappears on failure. An outage must not turn a real 404 into a 500.
Conversely, an uncached /posts/a-missing-url request that needed to ask the API whether the post existed returned 500 during the outage check. If the blog can't check whether a post really exists, returning 404 would send a crawler the same signal as "deleted" in case the post actually existed.
What the reproduction changed
I initially thought the post-page 404 was cached and the empty page after deployment appeared only on the first request. Neither matched the reproduction. At the time, post pages rendered on every request and recovered as soon as the API returned; empty pages after deployment persisted across requests. The notes called this roughly 60 seconds. The next post gives the request timings.
Part 5 had checked responses while cached content was available. This time I checked failures during revalidation and removed the code that turned them into empty lists.
The next post follows the build problem uncovered during this work: why the Docker image contained an empty blog.
Sources
- [S1] Incremental Static Regeneration | Next.js 15 Docs | Checked 2026-11-10 | https://nextjs.org/docs/15/app/guides/incremental-static-regeneration ↩
- [S2] How HTTP Status Codes Affect Google's Crawlers | Google for Developers | Checked 2026-11-10 | https://developers.google.com/crawling/docs/troubleshooting/http-status-codes ↩
- [S3] loading.js — Status Codes | Next.js 15 Docs | Checked 2026-11-10 | https://nextjs.org/docs/15/app/api-reference/file-conventions/loading ↩
- [S4] Control startup and shutdown order in Compose | Docker Docs | Checked 2026-11-10 | https://docs.docker.com/compose/how-tos/startup-order/ ↩
About these records
This post is based on a problem I found during a code review on August 26, 2026, my record of reproducing it with a mock API and real build output, and the results I checked on the production Mac the next day. The numbers come from the reproduction environment and from the production check respectively, and I keep the two apart. The post-fix excerpts were checked against the repository on November 10, 2026. I did not stop the production API again for this publication review.
Report an error or share feedback
Open a draft with this article’s title and URL. Review the message and recipient before sending.
Open email draftIf no email app opens, copy these details into your usual email service.
Related posts
Backend & Infrastructure Spring Boot 4.1 Jackson Settings: Comparing Duplicate JSON Keys and BigDecimal Output
Compare two Jackson settings in the same Spring Boot 4.1.0 app using the recorded six tests and six HTTP requests for duplicate JSON keys and BigDecimal notation.
Backend & Infrastructure A Spring Backend Learning Roadmap: Seven Skills to Demonstrate with a Small Service
A fictional reading-log service connects practice tasks and completion criteria for business rules, HTTP, transactions, permissions, queries, tests, and operations.