core icon indicating copy to clipboard operation
core copied to clipboard

Custom HttpStatusCode

Open emaborsa opened this issue 5 years ago • 3 comments

I'm writing a REST endpoint and I need to return a custom code:

Flight::halt(601, "UPDATE NEEDED");

Unfortunately I get:

500 Internal Server Error Invalid status code. (0) #0 C:\wamp64\www\cableparks\vendor\mikecao\flight\flight\Engine.php(397): flight\net\Response->status(601)

So I have to write:

Flight::stop(); header('HTTP/1.1 601 UPDATE NEEDED', true); return;

Is it possible to integrate custom status codes?

emaborsa avatar Feb 13 '20 09:02 emaborsa

Seems that 6xx error codes are not standard. So one option is map a function to throw this error code.

masakik avatar Feb 13 '20 10:02 masakik

Yes i know, but since PHP allows it, why isn`t it allowed in Flight?

emaborsa avatar Feb 13 '20 18:02 emaborsa

As @masakik said the 6xx error codes are not defined in the RFC. However, you can manually add it at the Response.php I guess.

seitsu avatar May 14 '20 08:05 seitsu

This could be added as a pull request if you want. There's a list of http status codes and we could add the 6xx if they are semi-standard

n0nag0n avatar Jan 13 '24 18:01 n0nag0n