10 * @author Evan Prodromou <evan@status.net>
11 * @author Zach Copley <zach@status.net>
12 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
13 * @link http://status.net/
15 * StatusNet - the distributed open-source microblogging tool
16 * Copyright (C) 2008, 2009, StatusNet, Inc.
18 * This program is free software: you can redistribute it and/or modify
19 * it under the terms of the GNU Affero General Public License as published by
20 * the Free Software Foundation, either version 3 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU Affero General Public License for more details.
28 * You should have received a copy of the GNU Affero General Public License
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
32 if (!defined('GNUSOCIAL')) {
37 * Class for displaying HTTP server errors
39 * Note: The older util.php class simply printed a string, but the spec
40 * says that 500 errors should be treated similarly to 400 errors, and
41 * it's easier to give an HTML response. Maybe we can customize these
42 * to display some funny animal cartoons. If not, we can probably role
43 * these classes up into a single class.
45 * See: http://tools.ietf.org/html/rfc2616#section-10
49 * @author Zach Copley <zach@status.net>
50 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
51 * @link http://status.net/
53 class ServerErrorAction extends ErrorAction
55 static $status = [500 => 'Internal Server Error',
56 501 => 'Not Implemented',
58 503 => 'Service Unavailable',
59 504 => 'Gateway Timeout',
60 505 => 'HTTP Version Not Supported'];
62 function __construct($message = 'Error', $code = 500, $ex = null)
64 parent::__construct($message, $code);
68 if (!$this->code || $this->code < 500 || $this->code > 599) {
69 $this->code = $this->default;
72 if (!$this->message) {
73 $this->message = "Server Error $this->code";
76 // Server errors must be logged.
77 $log = "ServerErrorAction: $code $message";
79 $log .= "\n" . $ex->getTraceAsString();
81 common_log(LOG_ERR, $log);
87 * To specify additional HTTP headers for the action
91 function extraHeaders()
93 $status_string = self::$status[$this->code];
94 header('HTTP/1.1 ' . $this->code . ' ' . $status_string);
100 * @return string page title
105 return self::$status[$this->code];