HTTPUnexpectedResponse.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. namespace Gogs\Lib\Curl\Exception {
  3. /**
  4. * Defines an unexpected response.
  5. *
  6. * @author Joachim M. Giaever (joachim[]giaever.org)
  7. * @package curl
  8. * @version 0.1.1
  9. */
  10. class HTTPUnexpectedResponse extends \Exception {
  11. /**
  12. * Includes valid codes, as a valid code can also be unexpeted.
  13. *
  14. * @var array $ecode HTTP status codes
  15. * @static
  16. */
  17. static $ecode = array(
  18. 0 => "Unknown error",
  19. 100 => 'Informational: Continue',
  20. 101 => 'Informational: Switching Protocols',
  21. 102 => 'Informational: Processing',
  22. 200 => 'Successful: OK',
  23. 201 => 'Successful: Created',
  24. 202 => 'Successful: Accepted',
  25. 203 => 'Successful: Non-Authoritative Information',
  26. 204 => 'Successful: No Content',
  27. 205 => 'Successful: Reset Content',
  28. 206 => 'Successful: Partial Content',
  29. 207 => 'Successful: Multi-Status',
  30. 208 => 'Successful: Already Reported',
  31. 226 => 'Successful: IM Used',
  32. 300 => 'Redirection: Multiple Choices',
  33. 301 => 'Redirection: Moved Permanently',
  34. 302 => 'Redirection: Found',
  35. 303 => 'Redirection: See Other',
  36. 304 => 'Redirection: Not Modified',
  37. 305 => 'Redirection: Use Proxy',
  38. 306 => 'Redirection: Switch Proxy',
  39. 307 => 'Redirection: Temporary Redirect',
  40. 308 => 'Redirection: Permanent Redirect',
  41. 400 => 'Client Error: Bad Request',
  42. 401 => 'Client Error: Unauthorized',
  43. 402 => 'Client Error: Payment Required',
  44. 403 => 'Client Error: Forbidden',
  45. 404 => 'Client Error: Not Found',
  46. 405 => 'Client Error: Method Not Allowed',
  47. 406 => 'Client Error: Not Acceptable',
  48. 407 => 'Client Error: Proxy Authentication Required',
  49. 408 => 'Client Error: Request Timeout',
  50. 409 => 'Client Error: Conflict',
  51. 410 => 'Client Error: Gone',
  52. 411 => 'Client Error: Length Required',
  53. 412 => 'Client Error: Precondition Failed',
  54. 413 => 'Client Error: Request Entity Too Large',
  55. 414 => 'Client Error: Request-URI Too Long',
  56. 415 => 'Client Error: Unsupported Media Type',
  57. 416 => 'Client Error: Requested Range Not Satisfiable',
  58. 417 => 'Client Error: Expectation Failed',
  59. 418 => 'Client Error: I\'m a teapot',
  60. 419 => 'Client Error: Authentication Timeout',
  61. 420 => 'Client Error: Enhance Your Calm',
  62. 420 => 'Client Error: Method Failure',
  63. 422 => 'Client Error: Unprocessable Entity',
  64. 423 => 'Client Error: Locked',
  65. 424 => 'Client Error: Failed Dependency',
  66. 424 => 'Client Error: Method Failure',
  67. 425 => 'Client Error: Unordered Collection',
  68. 426 => 'Client Error: Upgrade Required',
  69. 428 => 'Client Error: Precondition Required',
  70. 429 => 'Client Error: Too Many Requests',
  71. 431 => 'Client Error: Request Header Fields Too Large',
  72. 444 => 'Client Error: No Response',
  73. 449 => 'Client Error: Retry With',
  74. 450 => 'Client Error: Blocked by Windows Parental Controls',
  75. 451 => 'Client Error: Redirect',
  76. 451 => 'Client Error: Unavailable For Legal Reasons',
  77. 494 => 'Client Error: Request Header Too Large',
  78. 495 => 'Client Error: Cert Error',
  79. 496 => 'Client Error: No Cert',
  80. 497 => 'Client Error: HTTP to HTTPS',
  81. 499 => 'Client Error: Client Closed Request',
  82. 500 => 'Server Error: Internal Server Error',
  83. 501 => 'Server Error: Not Implemented',
  84. 502 => 'Server Error: Bad Gateway',
  85. 503 => 'Server Error: Service Unavailable',
  86. 504 => 'Server Error: Gateway Timeout',
  87. 505 => 'Server Error: HTTP Version Not Supported',
  88. 506 => 'Server Error: Variant Also Negotiates',
  89. 507 => 'Server Error: Insufficient Storage',
  90. 508 => 'Server Error: Loop Detected',
  91. 509 => 'Server Error: Bandwidth Limit Exceeded',
  92. 510 => 'Server Error: Not Extended',
  93. 511 => 'Server Error: Network Authentication Required',
  94. 598 => 'Server Error: Network read timeout error',
  95. 599 => 'Server Error: Network connect timeout error'
  96. );
  97. /**
  98. * The response from server (body)
  99. * @access private
  100. */
  101. private $response;
  102. /**
  103. * Sets the exceptions.
  104. *
  105. * @string $message - the response from the server.
  106. * @string $code - the HTTP status code.
  107. * @exception $prev - Previous exceptions
  108. **/
  109. public function __construct(string $message, int $code = 0, \Exception $previous = null) {
  110. $this->response = $message;
  111. parent::__construct(
  112. isset(HTTPUnexpectedResponse::$ecode[$code]) ? HTTPUnexpectedResponse::$ecode[$code] : HTTPUnexpectedResponse::$ecode[0],
  113. $code,
  114. $previous
  115. );
  116. }
  117. /**
  118. * Visual representation of the exception.
  119. *
  120. * @return string
  121. */
  122. public function __toString() {
  123. return __CLASS__ . ": [{$this->code} | {$this->message}]: {$this->response}\n";
  124. }
  125. /**
  126. * Get the actual response from the body or the request.
  127. *
  128. * @return string
  129. */
  130. public function getResponse() {
  131. return $this->response;
  132. }
  133. }
  134. }
  135. ?>