9 * @author Evan Prodromou <evan@status.net>
10 * @author Zach Copley <zach@status.net>
11 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
12 * @link http://status.net/
14 * StatusNet - the distributed open-source microblogging tool
15 * Copyright (C) 2008-2010 StatusNet, Inc.
17 * This program is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU Affero General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU Affero General Public License for more details.
27 * You should have received a copy of the GNU Affero General Public License
28 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
35 require_once INSTALLDIR . '/lib/error.php';
38 * Class for displaying HTTP client errors
42 * @author Zach Copley <zach@status.net>
43 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
44 * @link http://status.net/
46 class ClientErrorAction extends ErrorAction
48 static $status = array(400 => 'Bad Request',
49 401 => 'Unauthorized',
50 402 => 'Payment Required',
53 405 => 'Method Not Allowed',
54 406 => 'Not Acceptable',
55 407 => 'Proxy Authentication Required',
56 408 => 'Request Timeout',
59 411 => 'Length Required',
60 412 => 'Precondition Failed',
61 413 => 'Request Entity Too Large',
62 414 => 'Request-URI Too Long',
63 415 => 'Unsupported Media Type',
64 416 => 'Requested Range Not Satisfiable',
65 417 => 'Expectation Failed');
67 function __construct($message='Error', $code=400)
69 parent::__construct($message, $code);
73 // XXX: Should these error actions even be invokable via URI?
75 function handle(array $args=array())
77 parent::handle($args);
79 $this->code = $this->trimmed('code');
81 if (!$this->code || $code < 400 || $code > 499) {
82 $this->code = $this->default;
85 $this->message = $this->trimmed('message');
87 if (!$this->message) {
88 $this->message = "Client Error $this->code";
95 * To specify additional HTTP headers for the action
99 function extraHeaders()
101 $status_string = @self::$status[$this->code];
102 header('HTTP/1.1 '.$this->code.' '.$status_string);
113 return @self::$status[$this->code];