flightphp / core

An extensible micro-framework for PHP
https://docs.flightphp.com
MIT License
2.64k stars 407 forks source link

Custom HttpStatusCode #411

Closed emaborsa closed 9 months ago

emaborsa commented 4 years ago

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?

masakik commented 4 years ago

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

emaborsa commented 4 years ago

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

seitsu commented 4 years ago

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.

n0nag0n commented 9 months ago

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