Error actions use HTTP code name for title

Change the title of error actions to the HTTP code name, like
'internal server error'.
This commit is contained in:
Evan Prodromou 2009-03-04 06:27:30 -08:00
parent f9babf6a7d
commit cf4e1872ab
2 changed files with 22 additions and 13 deletions

View File

@ -49,7 +49,7 @@ class ClientErrorAction extends ErrorAction
function __construct($message='Error', $code=400) function __construct($message='Error', $code=400)
{ {
parent::__construct($message, $code); parent::__construct($message, $code);
$this->status = array(400 => 'Bad Request', $this->status = array(400 => 'Bad Request',
401 => 'Unauthorized', 401 => 'Unauthorized',
402 => 'Payment Required', 402 => 'Payment Required',
@ -72,7 +72,7 @@ class ClientErrorAction extends ErrorAction
} }
// XXX: Should these error actions even be invokable via URI? // XXX: Should these error actions even be invokable via URI?
function handle($args) function handle($args)
{ {
parent::handle($args); parent::handle($args);
@ -84,11 +84,16 @@ class ClientErrorAction extends ErrorAction
} }
$this->message = $this->trimmed('message'); $this->message = $this->trimmed('message');
if (!$this->message) { if (!$this->message) {
$this->message = "Client Error $this->code"; $this->message = "Client Error $this->code";
} }
$this->showPage(); $this->showPage();
} }
function title()
{
return $this->status[$this->code];
}
} }

View File

@ -42,7 +42,7 @@ require_once INSTALLDIR.'/lib/error.php';
* says that 500 errors should be treated similarly to 400 errors, and * says that 500 errors should be treated similarly to 400 errors, and
* it's easier to give an HTML response. Maybe we can customize these * it's easier to give an HTML response. Maybe we can customize these
* to display some funny animal cartoons. If not, we can probably role * to display some funny animal cartoons. If not, we can probably role
* these classes up into a single class. * these classes up into a single class.
* *
* See: http://tools.ietf.org/html/rfc2616#section-10 * See: http://tools.ietf.org/html/rfc2616#section-10
* *
@ -57,19 +57,19 @@ class ServerErrorAction extends ErrorAction
function __construct($message='Error', $code=500) function __construct($message='Error', $code=500)
{ {
parent::__construct($message, $code); parent::__construct($message, $code);
$this->status = array(500 => 'Internal Server Error', $this->status = array(500 => 'Internal Server Error',
501 => 'Not Implemented', 501 => 'Not Implemented',
502 => 'Bad Gateway', 502 => 'Bad Gateway',
503 => 'Service Unavailable', 503 => 'Service Unavailable',
504 => 'Gateway Timeout', 504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported'); 505 => 'HTTP Version Not Supported');
$this->default = 500; $this->default = 500;
} }
// XXX: Should these error actions even be invokable via URI? // XXX: Should these error actions even be invokable via URI?
function handle($args) function handle($args)
{ {
parent::handle($args); parent::handle($args);
@ -81,12 +81,16 @@ class ServerErrorAction extends ErrorAction
} }
$this->message = $this->trimmed('message'); $this->message = $this->trimmed('message');
if (!$this->message) { if (!$this->message) {
$this->message = "Server Error $this->code"; $this->message = "Server Error $this->code";
} }
$this->showPage(); $this->showPage();
} }
function title()
{
return $this->status[$this->code];
}
} }