I'm writing and API and I throw and Exception that calls a method to compose the header to return. If there isn't content I throw an Exception with a custom message and code 204.
throw new Exception("my message", 204);
And the method that composes the header
if ($status_codes[$code] !== null) {
$status_string = $code . ' ' . $status_codes[$code];
header($_SERVER['SERVER_PROTOCOL'] . ' ' . $status_string, true, $code);
if ($code != 200) die(json_encode(["code" => $code, "message" => $message]));
}
The problem is that when I use the code 204 I only show the status of the response that's a 204 No content
but my message with the code is not shown. I tried with the code 400 and it shows the custom message.
The 204 response MUST NOT include a message-body, and thus is always terminated by the first empty line after the header fields.
Need anymore words ? :)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments