Compare commits
2 commits
abfc2d227b
...
260b7666f4
Author | SHA1 | Date | |
---|---|---|---|
|
260b7666f4 | ||
|
945bf76d7d |
1 changed files with 14 additions and 6 deletions
20
src/Tpl.php
20
src/Tpl.php
|
@ -524,16 +524,21 @@ class Tpl {
|
||||||
/**
|
/**
|
||||||
* Display AJAX return
|
* Display AJAX return
|
||||||
* @param array|null $data AJAX returned data (optional)
|
* @param array|null $data AJAX returned data (optional)
|
||||||
|
* @param int|null $error_code HTTP error code (optional, default: 400 if not $data['success'])
|
||||||
* @param bool $pretty AJAX returned data
|
* @param bool $pretty AJAX returned data
|
||||||
* (optional, default: true if $_REQUEST['pretty'] is set, False otherwise)
|
* (optional, default: true if $_REQUEST['pretty'] is set, False otherwise)
|
||||||
* @return never
|
* @return never
|
||||||
*/
|
*/
|
||||||
public static function display_ajax_return($data=null, $pretty=false) {
|
public static function display_ajax_return($data=null, $error_code=null, $pretty=false) {
|
||||||
if (!is_array($data))
|
if (!is_array($data))
|
||||||
$data = array();
|
$data = array();
|
||||||
// Adjust HTTP error code on unsuccessfull request
|
|
||||||
elseif (isset($data['success']) && !$data['success'] && http_response_code() == 200)
|
// Adjust HTTP error code on unsuccessfull request (or if custom error code is provided)
|
||||||
http_response_code(400);
|
if (
|
||||||
|
$error_code
|
||||||
|
|| (isset($data['success']) && !$data['success'] && http_response_code() == 200)
|
||||||
|
)
|
||||||
|
http_response_code($error_code ? $error_code : 400);
|
||||||
|
|
||||||
$data['messages'] = self :: get_messages();
|
$data['messages'] = self :: get_messages();
|
||||||
if (!$data['messages']) unset($data['messages']);
|
if (!$data['messages']) unset($data['messages']);
|
||||||
|
@ -553,11 +558,12 @@ class Tpl {
|
||||||
/**
|
/**
|
||||||
* Display AJAX error
|
* Display AJAX error
|
||||||
* @param string|null $error Error message (optional)
|
* @param string|null $error Error message (optional)
|
||||||
|
* @param int|null $error_code HTTP error code (optional, default: 400)
|
||||||
* @param bool $pretty AJAX returned data
|
* @param bool $pretty AJAX returned data
|
||||||
* (optional, default: true if $_REQUEST['pretty'] is set, False otherwise)
|
* (optional, default: true if $_REQUEST['pretty'] is set, False otherwise)
|
||||||
* @return never
|
* @return never
|
||||||
*/
|
*/
|
||||||
public static function display_ajax_error($error=null, $pretty=false) {
|
public static function display_ajax_error($error=null, $error_code=null, $pretty=false) {
|
||||||
self :: display_ajax_return(
|
self :: display_ajax_return(
|
||||||
array(
|
array(
|
||||||
'success' => false,
|
'success' => false,
|
||||||
|
@ -566,7 +572,9 @@ class Tpl {
|
||||||
$error:
|
$error:
|
||||||
I18n::_("Unexpected error occured. If problem persist, please contact support.")
|
I18n::_("Unexpected error occured. If problem persist, please contact support.")
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
|
$error_code,
|
||||||
|
$pretty
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue