phalcon/cphalcon · error · Phalcon\Http\Response\Exceptions\NonStandardStatusCodeRequiresMessage

Non-standard status-code given without a message

Error message

Non-standard status-code given without a message

What it means

Response::setStatusCode(int $code, string $message = null) looks up a default reason phrase in the built-in IANA phrase table (getPhrases()). Codes with no entry in the table - 599, 499, custom codes - throw NonStandardStatusCodeRequiresMessage unless the second argument supplies the phrase.

Source

Thrown at phalcon/Http/Response.zep:708

        /**
         * We use HTTP/1.1 instead of HTTP/1.0
         *
         * Before that we would like to unset any existing HTTP/x.y headers
         */
        for key, _ in currentHeadersRaw {
            if typeof key == "string" && strstr(key, "HTTP/") {
                this->headers->remove(key);
            }
        }

        // if an empty message is given we try and grab the default for this
        // status code. If a default does not exist, stop here.
        if message === null {
            // See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
            let statusCodes = this->getPhrases();

            if unlikely !isset statusCodes[code] {
                throw new NonStandardStatusCodeRequiresMessage();
            }

            let defaultMessage = statusCodes[code],
                message        = defaultMessage;
        }

        this->headers->setRaw("HTTP/1.1 " . code . " " . message);

        /**
         * We also define a 'Status' header with the HTTP status
         */
        this->headers->set("Status", code . " " . message);

        return this;
    }
}

View on GitHub (pinned to b7419de9cd)

Solutions

  1. Pass the reason phrase: $response->setStatusCode(599, 'Network Connect Timeout');
  2. Use a standard code that has a default phrase (200, 400, 404, 422, 429, 503, ...)
  3. Carry custom semantics in the response body or a header instead of a non-standard status line

Example fix

// before
$response->setStatusCode(599); // no default phrase -> throws

// after
$response->setStatusCode(599, 'Upstream Timeout');
Defensive patterns

Strategy: validation

Validate before calling

$standard = [100,101,200,201,202,203,204,205,206,300,301,302,303,304,307,308,400,401,402,403,404,405,406,408,409,410,411,412,413,414,415,416,417,418,421,422,423,424,425,426,428,429,431,451,500,501,502,503,504,505,507,508];
if (in_array($code, $standard, true)) {
    $response->setStatusCode($code);
} else {
    $response->setStatusCode($code, $customMessage ?? 'Non-standard Status'); // message required
}

Try / catch

try { $response->setStatusCode($code); } catch (\Phalcon\Http\Response\Exceptions\NonStandardStatusCodeRequiresMessage $e) { $response->setStatusCode($code, 'Error'); // retry with explicit message
}

Prevention

When it happens

Trigger: $response->setStatusCode(599); setStatusCode(480); any code outside the shipped phrase map called without a message argument.

Common situations: Custom API status codes; the 599 'network timeout' convention used with upstream proxies; typos such as 220 in HTTP code paths.

Related errors


AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21). Data as JSON: /api/errors/bea88e1e977aac05. Report an issue: GitHub.