204 Error Code | Fix No-Content Responses Fast

The 204 error code means the request succeeded, but the server sent no response body, so your app must handle an empty payload.

A 204 response can feel odd. The request shows “success,” yet the UI has nothing to render. In most cases, nothing is “down.” You’re getting a response type that is built to carry no body.

This article explains what 204 means, when it’s the right status to return, and how to stop accidental no-content replies that confuse browsers, mobile apps, and API clients.

What A 204 No Content Status Code Means

In HTTP, 2xx codes signal success. A 204 is in that family, with one strict rule: the response must not include a message body. Clients should treat it as a completed action with nothing to parse. That’s why it’s labeled “No Content.”

A 204 response can still carry useful headers. You can return metadata like caching headers, an ETag, rate-limit headers, or a request ID. What you should not do is send JSON, HTML, or even a single character as the body. If a server tries to mix 204 with a payload, client behavior becomes inconsistent.

You’ll commonly see 204 used for actions where the client doesn’t need a new page or a new representation, like saving a preference, acknowledging a webhook, or deleting a record.

Why You See 204 When You Expected Data

Most “mystery 204s” come from a mismatch between what the client expects and what the server returns. The fix is to align the contract. Start by asking a plain question: is this endpoint meant to return data, or is it meant to confirm an action?

Empty Results Returned As No Content

Some APIs return 204 when a collection has no items. That can be awkward for clients that expect a JSON array. If “no items” is a normal state, a 200 with [] often fits better, since the endpoint still has a representation to return.

  • Pick One Shape — If callers expect a list, keep the response a list, even when it’s empty.
  • Test The Empty Case — Add a contract test that asserts status and body for zero results.
  • Document The Choice — Put the empty-state behavior in your API docs so clients don’t guess.

Middleware Or Proxies Rewriting Responses

A gateway, CDN rule, or proxy config can rewrite status codes. It might return 204 for a health check path, for OPTIONS preflights, or due to a blanket rule that was meant for another route.

  • Compare Origin And Edge — Call the origin directly, then call the public URL, and compare status and headers.
  • Scan For Return Rules — Search configs for directives that force 204 on certain paths or methods.
  • Check Cache Headers — A cached 204 can linger longer than you expect if cache rules allow it.

CORS Preflight Mix-Ups

Browsers send an OPTIONS request before some cross-origin calls. Many servers reply to that preflight with 204, which is fine. The trap is reading the preflight entry as if it were your real request.

  • Filter By Method — Separate OPTIONS from the actual GET, POST, or PATCH call in DevTools.
  • Confirm Allow Headers — Ensure the preflight response includes the Access-Control headers the browser asked for.

204 Error Code Fix Checklist For Developers

When a feature is “blank” and the network tab shows 204, you need a tight checklist you can run in minutes. These steps isolate the source without bouncing between layers at random.

  1. Confirm The Contract — Decide whether the route is supposed to return a body. Read the spec, then read the handler.
  2. Reproduce With Curl — Call the endpoint from a terminal so you can see raw status and headers.
  3. Log The Final Status — Add a log line at the last handler so you know what left the app.
  4. Trace Each Hop — Test origin, load balancer, gateway, then CDN to spot where the status changes.
  5. Review Client Parsing — Ensure the client does not call .json() or .text() when status is 204.

If 204 is intended, treat it as a successful empty response and move on. If it’s not intended, change the endpoint to return a representation with 200, or return an error status with a clear payload when something failed.

If a monitor flags the 204 error code as a failure, tune the alert. A spike can be normal for webhook acks, but odd for HTML pages or data feeds.

204 No Content Status Code Rules For APIs

204 works best when the success state is the result and the client already knows what changed. Think “saved,” “deleted,” “queued,” or “acknowledged.” It’s less suited for routes where the client needs data to render a screen.

The table below is a quick way to choose a status without surprising callers.

Status When It Fits Client Action
200 OK You return a body, even if it’s an empty list Parse the body as documented
201 Created You created a new resource with a URI Read Location, then parse body if present
204 No Content The action succeeded and no body is sent Skip parsing, update client state locally
304 Not Modified Cache validation says content is unchanged Use the cached representation
404 Not Found The resource does not exist at that URI Show not-found behavior or fallback UI

If you use 204 for “no rows found,” you force each client to branch. Many teams prefer returning 200 with an empty collection so callers can keep one decode path. If you keep 204 for that case, document it and test it in each client you ship.

For write operations, a 200 with the updated representation can reduce follow-up requests when the server computes fields like timestamps, totals, or derived flags. A 204 can be cleaner when the client already has the final state and just needs confirmation.

Server-Side Patterns That Prevent Accidental No Content

Accidental 204s tend to come from defaults. A handler returns nothing, a stack picks a status, and the client fails at parse time. Tighten your server behavior so each route returns a deliberate response on each path.

Make “No Return” A Build Error

In many stacks, a missing return value becomes a no-content success. That’s fine for action routes, but risky for data routes.

  • Return Explicit Results — Use response helpers that set status and body together, not ad-hoc returns.
  • Guard Missing Records — If an item is required, return a 404 or 422 with a structured error payload.
  • Write Contract Tests — Assert status code and body shape for success and error cases.

Use 204 Where It Shines

Webhook receivers and preflight endpoints are a good fit for 204 because the caller often needs only an acknowledgment.

  • Reply Fast — Confirm receipt with 204 when you accepted the event and no body is needed.
  • Send Required Headers — Include CORS headers and tracing headers even on empty responses.
  • Separate Processing — If work takes time, queue it and acknowledge quickly, then process out of band.

Watch Caching And Replays

CDNs can cache 204 responses if caching headers allow it, which can make a temporary empty reply look like a persistent bug. Be deliberate with cache settings on dynamic routes.

  • Set Cache-Control Clearly — For dynamic calls, use no-store or short max-age settings as needed.
  • Add A Request ID — Propagate an ID across app and edge layers so you can trace a single call end to end.

Client-Side Handling So Empty Success Doesn’t Break Code

On the client, the biggest trap is treating each 2xx as “there is JSON.” A 204 is successful, but parsing methods like response.json() can throw because there is no body to decode.

Fetch And Browser Apps

For fetch, treat 204 as a separate branch. If you want a unified return type, map it to null and let the caller decide what the UI should do next.

  • Branch On Status — If response.status === 204, return null and skip parsing.
  • Gate JSON Parsing — Only call .json() when status is not 204 and Content-Type is JSON.
  • Update State Locally — For delete or save actions, update the store without waiting for a payload.

Mobile Apps And SDK Clients

Mobile HTTP clients often use generic decoders. If your decoder always expects a body, a 204 can surface as a parse error that looks like a server failure.

  • Teach The Decoder “Empty” — Add a path that treats 204 as a successful empty result.
  • Log Status And Headers — Capture status and Content-Type so contract drift shows up fast.

For protocol detail, MDN’s 204 reference and the HTTP semantics RFC spell out intent and constraints.

MDN: 204 No Content and RFC 9110: HTTP Semantics

After you fix the contract, re-test the full user flow. Used in the right place, 204 keeps responses lean. Used in the wrong place, it leaves users staring at nothing.