API::returnError PHP Method

returnError() public method

Generic function to send a error message and an error code to client
public returnError ( $message = "Bad Request", $httpcode = 400, $statuscode = "ERROR", $docmessage = true, $return_response = true )
$message string message to send (human readable)(default 'Bad Request')
$httpcode integer http code (see : https://en.wikipedia.org/wiki/List_of_HTTP_status_codes) (default 400)
$statuscode string API status (to represend more precisely the current error) (default ERROR)
$docmessage boolean if true, add a link to inline document in message (default true)
$return_response boolean if true, the error will be send to returnResponse function (who may exit after sending data), otherwise, we will return an array with the error (default true)
    public function returnError($message = "Bad Request", $httpcode = 400, $statuscode = "ERROR", $docmessage = true, $return_response = true)
    {
        global $CFG_GLPI;
        if (empty($httpcode)) {
            $httpcode = 400;
        }
        if (empty($statuscode)) {
            $statuscode = "ERROR";
        }
        if ($docmessage) {
            $message .= "; " . sprintf(__("view documentation in your browser at %s"), self::$api_url . "/#{$statuscode}");
        }
        if ($return_response) {
            return $this->returnResponse(array($statuscode, $message), $httpcode);
        }
        return array($statuscode, $message);
    }