display_ajax_return(): Return HTTP 400 error code if success==false in retourned data

This commit is contained in:
Benjamin Renard 2021-07-28 17:16:43 +02:00
parent d76c21c526
commit 6d8812abb5

View file

@ -150,6 +150,10 @@ function display_ajax_return($data=null, $pretty=false) {
global $debug_ajax;
if (is_null($data))
$data = array();
// Adjust HTTP error code on unsuccessfull request
elseif (isset($data['success']) && !$data['success'] && http_response_code() == 200)
http_response_code(400);
if (isset($_SESSION['messages']) && !empty($_SESSION['messages'])) {
$data['messages'] = $_SESSION['messages'];
unset($_SESSION['messages']);