Welcome Guest, Not a member yet? Register   Sign In
Exceptions::show_error() + set_status_header() + custom error codes
#1

[eluser]coolfactor[/eluser]
The Exceptions library is meant to facilitate the use of exceptions in a CodeIgniter application. And PHP-based exceptions, like many other languages, are designed to be extended and assigned custom error codes. However, with CodeIgniter, when one attempts to display one of these custom exceptions using the provided show_error() page, it may fail.

The first line in the show_error() function is to call set_status_header($code), passing an HTTP status code. So this breaks down when passing in my own custom error code. The code is not recognized, which generates a new error, displaying the text "No status text available. Please check your status code number or supply your own message text." instead of the exception message that I provided. There doesn't seem to be a way to provide additional error code-to-text mappings and this set_status_header() function can not be overridden.

Flow:
Exception handler --> show_error() --> set_status_header() --> fail.

Two solutions without any changes to CodeIgniter:
1. I could avoid using show_error() for my custom exceptions entirely and write my own method.
2. I could avoid passing in the custom error code into show_error()'s parameter and stay with a known HTTP status code.

But the fact that a "general method" for showing errors is tied into a hard-coded method for sending an HTTP status code to the browser seems to be a bit restrictive. I think the call to set_status_header() should be conditional and that it <b>need not display its own error message</b> if the code it was passed is not recognized. It should only send known HTTP status codes to the browser. Of course, this flexibility also opens up a can of worms when a custom exception code happens to be the same as a known HTTP status code... hmmm.


Messages In This Thread
Exceptions::show_error() + set_status_header() + custom error codes - by El Forum - 09-12-2010, 12:00 PM



Theme © iAndrew 2016 - Forum software by © MyBB