Welcome Guest, Not a member yet? Register   Sign In
HTTP error codes for php syntax and sql errors
#1

[eluser]ricick[/eluser]
Is there away to get codeigniter to return 500 range status codes when an error is encountered rather than 200, along with the human readable error description?
#2

[eluser]Clooner[/eluser]
[quote author="ricick" date="1238153944"]Is there away to get codeigniter to return 500 range status codes when an error is encountered rather than 200, along with the human readable error description?[/quote] Using $this->output->set_status_header('500'); will return a 500 error header.
#3

[eluser]ricick[/eluser]
Yes but that's a manually returned code. What I mean is an internal code error. e.g.

$this->db->get('wrongtablename');

or

this->>oopsIMadeASyntaxError;

will print a human freindly error message, but the status code returned will be 200.
#4

[eluser]Clooner[/eluser]
[quote author="ricick" date="1238161842"]Yes but that's a manually returned code. What I mean is an internal code error. e.g.

$this->db->get('wrongtablename');

or

this->>oopsIMadeASyntaxError;

will print a human freindly error message, but the status code returned will be 200.[/quote]
Under the applications/errors dir you can edit how your errors are displayed/handled!
#5

[eluser]ricick[/eluser]
That's perfect for database and php errors. Is there a way to get this to work for syntax errors too? It doesn't seem to use any of the error pages in this case. It just prints:

Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\htdocs\mysite\api\system\application\controllers\broken.php on line 22

However the status code is still 200.
#6

[eluser]Aea[/eluser]
I don't believe global error handlers can catch Parse errors, since they appear long before any code is run. It's unrealistic to expect code to be executed when the interpreter doesn't even know what you want.
#7

[eluser]ricick[/eluser]
So surely the interpreter should return and error code. Perhaps this is a php config setting?
#8

[eluser]Aea[/eluser]
No, the interpreter is throwing a parser error because... you obviously did something very wrong and it doesn't know what you meant and thus throws an error. When you have a parse error no code is ever executed, try it...

Code:
<?php

echo 'Parse Error, No Execution...'.PHP_EOL;
ob_flush();

$str = = ;

Code:
php parse.php

Parse error: syntax error, unexpected '=' in /Users/aea/Desktop/PHP Examples/parse.php on line 6
#9

[eluser]ricick[/eluser]
I get that. What I don't understand is why this comes back with a 200 code. Can't you configure the interpreter to fire an error code, along with the error message in the body
#10

[eluser]Aea[/eluser]
I would contend with your claim of understanding, the interpreter runs before your code is executed, if there is a parse error your code is not run. Now I'm sure you could, with a bit of effort change the PHP Core to fire off error codes instead of plain text errors. I am fairly certain this isn't something that you can just configure.

Also, it's a terrible practice to push broken code to where a user can access it. I just can't imagine a situation where you'd want to catch parser errors and send a 500 request, why not eliminate the parse errors before you allow the code to be user accessible?




Theme © iAndrew 2016 - Forum software by © MyBB