servererroraction.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * Server error action.
  4. *
  5. * PHP version 5
  6. *
  7. * @category Action
  8. * @package StatusNet
  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/
  13. *
  14. * StatusNet - the distributed open-source microblogging tool
  15. * Copyright (C) 2008, 2009, StatusNet, Inc.
  16. *
  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.
  21. *
  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.
  26. *
  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/>.
  29. */
  30. if (!defined('GNUSOCIAL')) { exit(1); }
  31. /**
  32. * Class for displaying HTTP server errors
  33. *
  34. * Note: The older util.php class simply printed a string, but the spec
  35. * says that 500 errors should be treated similarly to 400 errors, and
  36. * it's easier to give an HTML response. Maybe we can customize these
  37. * to display some funny animal cartoons. If not, we can probably role
  38. * these classes up into a single class.
  39. *
  40. * See: http://tools.ietf.org/html/rfc2616#section-10
  41. *
  42. * @category Action
  43. * @package StatusNet
  44. * @author Zach Copley <zach@status.net>
  45. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  46. * @link http://status.net/
  47. */
  48. class ServerErrorAction extends ErrorAction
  49. {
  50. static $status = array(500 => 'Internal Server Error',
  51. 501 => 'Not Implemented',
  52. 502 => 'Bad Gateway',
  53. 503 => 'Service Unavailable',
  54. 504 => 'Gateway Timeout',
  55. 505 => 'HTTP Version Not Supported');
  56. function __construct($message='Error', $code=500, $ex=null)
  57. {
  58. parent::__construct($message, $code);
  59. $this->default = 500;
  60. if (!$this->code || $this->code < 500 || $this->code > 599) {
  61. $this->code = $this->default;
  62. }
  63. if (!$this->message) {
  64. $this->message = "Server Error $this->code";
  65. }
  66. // Server errors must be logged.
  67. $log = "ServerErrorAction: $code $message";
  68. if ($ex) {
  69. $log .= "\n" . $ex->getTraceAsString();
  70. }
  71. common_log(LOG_ERR, $log);
  72. $this->showPage();
  73. }
  74. /**
  75. * To specify additional HTTP headers for the action
  76. *
  77. * @return void
  78. */
  79. function extraHeaders()
  80. {
  81. $status_string = @self::$status[$this->code];
  82. header('HTTP/1.1 '.$this->code.' '.$status_string);
  83. }
  84. /**
  85. * Page title.
  86. *
  87. * @return page title
  88. */
  89. function title()
  90. {
  91. return @self::$status[$this->code];
  92. }
  93. }