diff --git a/src/frapi/library/Frapi/Error.php b/src/frapi/library/Frapi/Error.php index fdb1877..077421c 100644 --- a/src/frapi/library/Frapi/Error.php +++ b/src/frapi/library/Frapi/Error.php @@ -244,11 +244,22 @@ private static function _get($error_name, $error_msg = false, $http_code = false if ($http_phrase !== false) { $error['http_phrase'] = $http_phrase; + } else if (isset(Frapi_Response::$http_reason[$error['http_code']])){ + $error['http_phrase'] = Frapi_Response::$http_reason[$error['http_code']]; + } else if ($error['message'] !== false) { + $error['http_phrase'] = $error['message']; } - return $error; } + if ($http_phrase === false) { + if (isset(Frapi_Response::$http_reason[$http_code])) { + $http_phrase = Frapi_Response::$http_reason[$http_code]; + } else if ($error_msg !== false) { + $http_phrase = $error_msg; + } + } + return array( 'name' => $error_name, 'message' => $error_msg !== false ? $error_msg : $error_name, diff --git a/src/frapi/library/Frapi/Response.php b/src/frapi/library/Frapi/Response.php index ab3fd6d..8ebd3f5 100644 --- a/src/frapi/library/Frapi/Response.php +++ b/src/frapi/library/Frapi/Response.php @@ -50,6 +50,59 @@ class Frapi_Response */ protected $data = array(); + /** + * Mapping of http code to reason phrases + * + * Standard http codes to standard reason phrase mapping + * + * @var array + */ + public static $http_reason = array ( + 100 => 'Continue', + 101 => 'Switching Protocols', + 103 => 'Checkpoint', + 200 => 'OK', + 201 => 'Created', + 202 => 'Accepted', + 203 => 'Non-Authoritative Information', + 204 => 'No Content', + 205 => 'Reset Content', + 206 => 'Partial Content', + 300 => 'Multiple Choices', + 301 => 'Moved Permanently', + 302 => 'Found', + 303 => 'See Other', + 304 => 'Not Modified', + 306 => 'Switch Proxy', + 307 => 'Temporary Redirect', + 308 => 'Resume Incomplete', + 400 => 'Bad Request', + 401 => 'Unauthorized', + 402 => 'Payment Required', + 403 => 'Forbidden', + 404 => 'Not Found', + 405 => 'Method Not Allowed', + 406 => 'Not Acceptable', + 407 => 'Proxy Authentication Required', + 408 => 'Request Timeout', + 409 => 'Conflict', + 410 => 'Gone', + 411 => 'Length Required', + 412 => 'Precondition Failed', + 413 => 'Request Entity Too Large', + 414 => 'Request-URI Too Long', + 415 => 'Unsupported Media Type', + 416 => 'Requested Range Not Satisfiable', + 417 => 'Expectation Failed', + 500 => 'Internal Server Error', + 501 => 'Not Implemented', + 502 => 'Bad Gateway', + 503 => 'Service Unavailable', + 504 => 'Gateway Timeout', + 505 => 'HTTP Version Not Supported', + 511 => 'Network Authentication Required', + ); + /** * The constructor * @@ -78,6 +131,8 @@ public function __construct(array $response) if (isset($response['reason_phrase'])) { $this->http_phrase = $response['reason_phrase']; + } else if (isset(self::$http_reason[$this->http_code])){ + $this->http_phrase = self::$http_reason[$this->http_code]; } if (isset($response['data'])) {