Catch script output/warnings
This commit is contained in:
parent
6ccd38cc9b
commit
05124129b5
2 changed files with 31 additions and 4 deletions
|
@ -11,6 +11,8 @@ use wishthis\{User, Wish, EmbedCache};
|
||||||
$api = true;
|
$api = true;
|
||||||
$response = array();
|
$response = array();
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
|
||||||
require '../../index.php';
|
require '../../index.php';
|
||||||
|
|
||||||
switch ($_SERVER['REQUEST_METHOD']) {
|
switch ($_SERVER['REQUEST_METHOD']) {
|
||||||
|
@ -34,7 +36,7 @@ switch ($_SERVER['REQUEST_METHOD']) {
|
||||||
$exists = $cache->exists() ? 'true' : 'false';
|
$exists = $cache->exists() ? 'true' : 'false';
|
||||||
|
|
||||||
$response = array(
|
$response = array(
|
||||||
'info' => $info
|
'info' => $info,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -117,6 +119,8 @@ switch ($_SERVER['REQUEST_METHOD']) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$response['warning'] = ob_get_clean();
|
||||||
|
|
||||||
header('Content-type: application/json; charset=utf-8');
|
header('Content-type: application/json; charset=utf-8');
|
||||||
echo json_encode($response);
|
echo json_encode($response);
|
||||||
die();
|
die();
|
||||||
|
|
|
@ -125,14 +125,19 @@ function handleFetchResponse(response) {
|
||||||
var isJSON = response.headers.get('content-type')?.includes('application/json');
|
var isJSON = response.headers.get('content-type')?.includes('application/json');
|
||||||
|
|
||||||
if (isText) {
|
if (isText) {
|
||||||
return response.text()
|
return response.text().then(function(text) {
|
||||||
.then(function(text) {
|
|
||||||
if (text.toLowerCase().includes('error') || text.toLowerCase().includes('exception')) {
|
if (text.toLowerCase().includes('error') || text.toLowerCase().includes('exception')) {
|
||||||
showError(text);
|
showError(text);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else if (isJSON) {
|
} else if (isJSON) {
|
||||||
return response.json();
|
return response.json().then(function(json) {
|
||||||
|
if (json.warning) {
|
||||||
|
showWarning(json.warning)
|
||||||
|
}
|
||||||
|
|
||||||
|
return json;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,3 +164,21 @@ function showError(error) {
|
||||||
autoShow: true
|
autoShow: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function showWarning(warning) {
|
||||||
|
warning = warning.replace('<br />', '');
|
||||||
|
|
||||||
|
$('body')
|
||||||
|
.modal({
|
||||||
|
title : 'Warning',
|
||||||
|
content : warning,
|
||||||
|
class : '',
|
||||||
|
actions : [
|
||||||
|
{
|
||||||
|
text: 'Understood',
|
||||||
|
class: 'primary'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
autoShow: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue