Source of file RESTfulAPI_Error.php
Size: 2,305 Bytes - Last Modified: 2021-12-24T06:44:03+00:00
/var/www/docs.ssmods.com/process/src/code/RESTfulAPI_Error.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 | <?php /** * Stores an API errors. And a library of static methods. * * @author Thierry Francois @colymba thierry@colymba.com * @copyright Copyright (c) 2013, Thierry Francois * * @license http://opensource.org/licenses/BSD-3-Clause BSD Simplified * * @package RESTfulAPI * @subpackage Error */ class RESTfulAPI_Error { /** * Error HTTP status code * * @var integer */ public $code; /** * Error message * * @var string */ public $message; /** * Error response body * to be serialized * * @var mixed */ public $body; /** * Creates the error object and sets properties * * @param integer $code HTTP status code * @param string $message Error message */ public function __construct($code, $message, $body = null) { $this->code = $code; $this->message = $message; if ($body !== null) { $this->body = $body; } else { $this->body = array( 'code' => $code, 'message' => $message ); } } /** * Check for the latest JSON parsing error * and return the message if any * * More available for PHP >= 5.3.3 * http://www.php.net/manual/en/function.json-last-error.php * * @return false|string Returns false if no error or a string with the error detail. */ public static function get_json_error() { $error = 'JSON - '; switch (json_last_error()) { case JSON_ERROR_NONE: $error = false; break; case JSON_ERROR_DEPTH: $error .= 'The maximum stack depth has been exceeded.'; break; case JSON_ERROR_STATE_MISMATCH: $error .= 'Invalid or malformed JSON.'; break; case JSON_ERROR_CTRL_CHAR: $error .= 'Control character error, possibly incorrectly encoded.'; break; case JSON_ERROR_SYNTAX: $error .= 'Syntax error.'; break; default: $error .= 'Unknown error ('.json_last_error().').'; break; } return $error; } } |