OpenUptime

200 OK, but the page is broken

A status code says the server answered, not that the answer is right. Error pages served with 200, cached fallbacks, empty lists and "degraded" flags all pass a check that only looks at the status. This guide shows how to catch them.

Where it happens

  • Error pages with 200. A framework or CDN renders "Something went wrong" or a maintenance page and keeps the 200.
  • Fallback content. A cache or service worker serves an old copy when the origin fails.
  • Partial outages. An API answers, but a field says "degraded", a list is empty, or a dependency is marked down.
  • Login walls. An expired session or a changed auth rule returns the sign-in page with 200 instead of the content.

Reproduce it

Compare a healthy answer with a broken one. Both return 200:

$ curl -s https://api.example.com/status
{ "data": { "status": "ok", "queue": { "depth": 12 } }, "version": "2026.11.2" }
$ curl -s -w "\nstatus %{http_code}\n" https://api.example.com/status
{ "data": { "status": "degraded", "queue": { "depth": 48210 } },
  "error": "database read-only" }
status 200

Decide which value tells you the service works, then test exactly that. With jq, the exit code is the verdict:

curl -s https://api.example.com/status | jq -e '.data.status == "ok"'
# exit code 0 when healthy, 1 when not: usable in any script or CI step

For HTML pages: a keyword

On an HTTP monitor, fill Response must contain (optional) with text that only a working page has, such as a product name in the page body or the label of a button. Choose must not contain instead to fail when an error text appears, such as "Service unavailable". The match is case-sensitive.

Pick text that is produced by the part you want to check. The site name in the header is also on the error page, so it proves nothing.

For JSON APIs: assertions

Under JSON assertions (optional), add up to 10 rules. Each reads a value with a path such as $.data.items[0].status and compares it with equals, not_equals, contains, exists, not_exists, greater_than or less_than. Numbers, true, false and null compare as typed. Every rule must hold for the check to pass. The same monitor over the API:

curl -X POST https://openuptime.app/api/monitors \
  -H "x-api-key: ou_..." -H "Content-Type: application/json" \
  -d '{
    "name": "Status API",
    "type": "http",
    "target": "https://api.example.com/status",
    "intervalSec": 60,
    "jsonAssertions": [
      { "path": "$.data.status", "op": "equals", "value": "ok" },
      { "path": "$.data.queue.depth", "op": "less_than", "value": "1000" },
      { "path": "$.error", "op": "not_exists" }
    ]
  }'

When a rule fails, the check reports the first one that did not hold, for example Expected JSON $.data.status to equal "ok", got "degraded", so the incident tells you what broke before you open a log. Values are written as text, as in "1000", and compared by type.

Make the check meaningful

  • Check an endpoint that touches the things that break: a status route that reads from the database tells you more than a static /ping.
  • Keep the expected status strict. Leave it at 2xx, or set the one code you expect, so a redirect to a login page does not pass.
  • If the endpoint needs a token, add it as a request header on the monitor; use a read-only token made for monitoring.

See API monitoring for what else an HTTP monitor can check.

返回 200,页面却坏了

状态码只说明服务器回应了,不说明回应是对的。用 200 返回的错误页、缓存的兜底内容、空列表和“degraded”标记,都能通过只看状态码的检测。本文介绍如何发现它们。

常见场景

  • 带 200 的错误页。框架或 CDN 渲染出“出错了”或维护页面,状态码仍是 200。
  • 兜底内容。源站失败时,缓存或 Service Worker 返回旧的副本。
  • 部分故障。API 有响应,但某个字段是 "degraded"、列表为空,或某个依赖被标记为不可用。
  • 登录拦截。会话过期或认证规则变化后,返回的是 200 的登录页而不是正文。

复现问题

对比正常和异常的两个响应,它们都返回 200:

$ curl -s https://api.example.com/status
{ "data": { "status": "ok", "queue": { "depth": 12 } }, "version": "2026.11.2" }
$ curl -s -w "\nstatus %{http_code}\n" https://api.example.com/status
{ "data": { "status": "degraded", "queue": { "depth": 48210 } },
  "error": "database read-only" }
status 200

先确定哪个值能说明服务正常,然后只检查这个值。用 jq 时,退出码就是结论:

curl -s https://api.example.com/status | jq -e '.data.status == "ok"'
# exit code 0 when healthy, 1 when not: usable in any script or CI step

HTML 页面:关键词

在 HTTP 监控的响应内容须包含(可选)中,填入只有正常页面才有的文本,例如正文里的产品名或某个按钮的文字。也可以选择必须不含,在出现错误文本(如“Service unavailable”)时判定失败。匹配区分大小写。

选的文本要由你想检查的那部分生成。页头里的网站名在错误页上也有,起不到作用。

JSON API:断言

在 JSON 断言(可选)中最多添加 10 条规则。每条用 $.data.items[0].status 这样的路径读取一个值,再用 equals、not_equals、contains、exists、not_exists、greater_than 或 less_than 比较。数字、true、false 和 null 按类型比较。所有规则都成立,检测才算通过。通过 API 创建同样的监控:

curl -X POST https://openuptime.app/api/monitors \
  -H "x-api-key: ou_..." -H "Content-Type: application/json" \
  -d '{
    "name": "Status API",
    "type": "http",
    "target": "https://api.example.com/status",
    "intervalSec": 60,
    "jsonAssertions": [
      { "path": "$.data.status", "op": "equals", "value": "ok" },
      { "path": "$.data.queue.depth", "op": "less_than", "value": "1000" },
      { "path": "$.error", "op": "not_exists" }
    ]
  }'

规则失败时,检测会报告第一条不成立的规则,例如 Expected JSON $.data.status to equal "ok", got "degraded",你在打开日志之前就能从事件里看出哪里坏了。期望值以文本形式填写,如 "1000",比较时按类型进行。

让检测有意义

  • 检测会涉及易出问题环节的端点:读取数据库的状态接口比静态的 /ping 更能说明问题。
  • 期望状态码保持严格。保持 2xx,或设置你期望的那一个状态码,避免跳转到登录页也能通过。
  • 如果端点需要令牌,在监控中添加请求头;请使用专为监控创建的只读令牌。

更多 HTTP 监控能检查的内容,见 API 监控。

Last updated 2026-11-16最后更新:2026-11-16