Skip to content

Commit

Permalink
Update Utilities.php
Browse files Browse the repository at this point in the history
  • Loading branch information
viames committed Jul 19, 2024
1 parent ca2b333 commit 5ba3e94
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/Utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,26 @@ public static function varToText($var, bool $showTypes=TRUE, ?int $indent=0): st
* Proxy method to print a JSON error message.
*
* @param string Error message to print on user.
* @param int|NULL Error code (optional).
* @param int|NULL HTTP code (optional).
* @return void
*/
public static function printJsonError(string $message): void {
public static function printJsonError(string $message, ?int $code=NULL, ?int $httpCode=NULL): void {

self::printJsonMessage($message, TRUE);
$logger = Logger::getInstance();

$ret = new \stdClass();
$ret->message = $message;
$ret->error = TRUE;
$ret->code = $code;
$ret->log = $logger->getEventListForAjax();
$json = json_encode($ret);
if (is_int($httpCode)) {
http_response_code($httpCode);
}
header('Content-Type: application/json', TRUE);
print $json;
die();

}

Expand Down

0 comments on commit 5ba3e94

Please sign in to comment.