louislam/uptime-kuma · error · Error

Accepted status codes must be valid JSON: ${e.message}

Error message

Accepted status codes must be valid JSON: ${e.message}

What it means

validate() runs JSON.parse on accepted_statuscodes_json. It must be a JSON array of status-code range strings (e.g. ["2xx","3xx"]).

Source

Thrown at server/model/monitor.js:1689

                JSON.parse(this.conditions);
            } catch (e) {
                throw new Error(`Conditions must be valid JSON: ${e.message}`);
            }
        }

        if (this.headers) {
            try {
                JSON.parse(this.headers);
            } catch (e) {
                throw new Error(`Headers must be valid JSON: ${e.message}`);
            }
        }

        if (this.accepted_statuscodes_json) {
            try {
                JSON.parse(this.accepted_statuscodes_json);
            } catch (e) {
                throw new Error(`Accepted status codes must be valid JSON: ${e.message}`);
            }
        }

        if (["system-service", "pm2"].includes(this.type)) {
            this.system_service_name = (this.system_service_name || "").trim();

            if (!this.system_service_name) {
                throw new Error(this.type === "pm2" ? "PM2 process name is required." : "Service Name is required.");
            }
        }

        if (this.type === "system-service" && !/^[a-zA-Z0-9._\-@]+$/.test(this.system_service_name)) {
            throw new Error("Invalid service name. Please use the internal Service Name (no spaces).");
        }

        if (this.type === "pm2" && /[\u0000-\u001F\u007F]/.test(this.system_service_name)) {
            throw new Error("Invalid PM2 process name.");
        }

View on GitHub (pinned to 6b5ea01557)

Solutions

  1. Provide accepted status codes as a JSON array: ["2xx","3xx"]
  2. Validate with JSON.parse before saving

Example fix

// before
monitor.accepted_statuscodes_json = "2xx,3xx";

// after
monitor.accepted_statuscodes_json = '["2xx","3xx"]';
Defensive patterns

Strategy: validation

Validate before calling

if (monitor.accepted_statuscodes_json) {
  const v = JSON.parse(monitor.accepted_statuscodes_json);
  if (!Array.isArray(v)) throw new Error("accepted status codes must be a JSON array");
}

Type guard

function isValidStatusCodes(v) {
  if (!v) return true;
  try { return Array.isArray(JSON.parse(v)); } catch { return false; }
}

Try / catch

try { monitor.validate(); await save(monitor); } catch (e) { /* surface e.message */ }

Prevention

When it happens

Trigger: accepted_statuscodes_json is not valid JSON, e.g. a comma-separated string or a legacy non-JSON representation.

Common situations: Manual API call passing comma-separated codes; field populated by an older version or fork with a different format.

Related errors


AI-assisted analysis of louislam/uptime-kuma@6b5ea01557 (2026-08-12). Data as JSON: /api/errors/c5c33aa8eeea2f56. Report an issue: GitHub.