{"record":{"id":"bea88e1e977aac05","repo":"phalcon/cphalcon","slug":"non-standard-status-code-given-without-a-message","errorCode":null,"errorMessage":"Non-standard status-code given without a message","messagePattern":"Non-standard status-code given without a message","errorType":"exception","errorClass":"Phalcon\\Http\\Response\\Exceptions\\NonStandardStatusCodeRequiresMessage","httpStatus":null,"severity":"error","filePath":"phalcon/Http/Response.zep","lineNumber":708,"sourceCode":"        /**\n         * We use HTTP/1.1 instead of HTTP/1.0\n         *\n         * Before that we would like to unset any existing HTTP/x.y headers\n         */\n        for key, _ in currentHeadersRaw {\n            if typeof key == \"string\" && strstr(key, \"HTTP/\") {\n                this->headers->remove(key);\n            }\n        }\n\n        // if an empty message is given we try and grab the default for this\n        // status code. If a default does not exist, stop here.\n        if message === null {\n            // See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml\n            let statusCodes = this->getPhrases();\n\n            if unlikely !isset statusCodes[code] {\n                throw new NonStandardStatusCodeRequiresMessage();\n            }\n\n            let defaultMessage = statusCodes[code],\n                message        = defaultMessage;\n        }\n\n        this->headers->setRaw(\"HTTP/1.1 \" . code . \" \" . message);\n\n        /**\n         * We also define a 'Status' header with the HTTP status\n         */\n        this->headers->set(\"Status\", code . \" \" . message);\n\n        return this;\n    }\n}\n","sourceCodeStart":690,"sourceCodeEnd":725,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Http/Response.zep#L690-L725","documentation":"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.","triggerScenarios":"$response->setStatusCode(599); setStatusCode(480); any code outside the shipped phrase map called without a message argument.","commonSituations":"Custom API status codes; the 599 'network timeout' convention used with upstream proxies; typos such as 220 in HTTP code paths.","solutions":["Pass the reason phrase: $response->setStatusCode(599, 'Network Connect Timeout');","Use a standard code that has a default phrase (200, 400, 404, 422, 429, 503, ...)","Carry custom semantics in the response body or a header instead of a non-standard status line"],"exampleFix":"// before\n$response->setStatusCode(599); // no default phrase -> throws\n\n// after\n$response->setStatusCode(599, 'Upstream Timeout');","handlingStrategy":"validation","validationCode":"$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];\nif (in_array($code, $standard, true)) {\n    $response->setStatusCode($code);\n} else {\n    $response->setStatusCode($code, $customMessage ?? 'Non-standard Status'); // message required\n}","typeGuard":null,"tryCatchPattern":"try { $response->setStatusCode($code); } catch (\\Phalcon\\Http\\Response\\Exceptions\\NonStandardStatusCodeRequiresMessage $e) { $response->setStatusCode($code, 'Error'); // retry with explicit message\n}","preventionTips":["Treat the status-code message argument as mandatory for any code outside the IANA defaults","Keep a project constant list of allowed status codes","Put custom API semantics in the body or headers, not the status line"],"tags":["php","phalcon","response","http","status-code"],"backgroundTag":"unknown-http-status-code","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}