Another only "200 response" question

I get a 200 status even when I set it to 500.

When I pass a simple string like:

return $response->withStatus(500, "bli bla blo");

I get my 500.

When I put that string into a variable like:

$x = "bli bla blo";
return $response->withStatus(500, $x);

I get my 500 as well.

But when I try use

return $response->withStatus(500, $e->getMessage());

I get a 200 instead of 500.

I tried to cast to string with (string)$e->getMessage() and concatinate that to a “test” but I still get a 200.

What could be going wrong here?

Okay, I found it:
According to rfc2616 Reason-Phrase can not contain CR and LF (\r \n). My variable had them apparently.

Try: return $response->withStatus(500)->write($e->getMessage())); which will only work with Slim’s response object.