Log non JSON API responses

This commit is contained in:
Mikei386
2026-06-23 07:04:43 +02:00
parent d7a62eb15e
commit 7cddfb19a4
7 changed files with 44 additions and 11 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
set -eu
PLUGIN="u-navigator"
VERSION="2026.06.23.r006"
VERSION="2026.06.23.r007"
PKG_DIR="packages"
WORK_DIR=".plugin-build"
PKG_NAME="${PLUGIN}-${VERSION}.tgz"
Binary file not shown.
Binary file not shown.
@@ -32,6 +32,14 @@ function unav_read_only(): bool {
return getenv('U_NAV_READ_ONLY') === '1';
}
function unav_function_available(string $name): bool {
if (!function_exists($name)) {
return false;
}
$disabled = array_map('trim', explode(',', (string)ini_get('disable_functions')));
return !in_array($name, $disabled, true);
}
function unav_json($payload, int $status = 200): void {
http_response_code($status);
header('Content-Type: application/json; charset=utf-8');
@@ -35,11 +35,22 @@ unav_job_write($job);
$worker = __DIR__ . '/job_worker.php';
$php = is_executable('/usr/bin/php') ? '/usr/bin/php' : (PHP_BINARY ?: 'php');
if (function_exists('exec') && is_file($worker)) {
exec(escapeshellarg($php) . ' ' . escapeshellarg($worker) . ' ' . escapeshellarg($id) . ' > /dev/null 2>&1 &');
} else {
require $worker;
$started = false;
if (unav_function_available('exec') && is_file($worker)) {
try {
$exitCode = 0;
@exec(escapeshellarg($php) . ' ' . escapeshellarg($worker) . ' ' . escapeshellarg($id) . ' > /dev/null 2>&1 &', $output, $exitCode);
$started = ($exitCode === 0);
} catch (Throwable $error) {
$started = false;
}
}
if (!$started) {
require_once $worker;
unav_run_job($id);
$job = unav_job_read($id);
}
unav_json($job, 202);
+18 -4
View File
@@ -826,10 +826,17 @@ function startResizeWindow(event, win) {
async function api(url, options) {
const response = await fetchChecked(url, options);
const text = await response.text();
try {
return await response.json();
return JSON.parse(text);
} catch (error) {
recordDebug('api.json.error', { url, error: serializeError(error) });
recordDebug('api.json.error', {
url,
status: response.status,
contentType: response.headers.get('content-type'),
body: text.slice(0, 2000),
error: serializeError(error)
});
throw error;
}
}
@@ -837,12 +844,19 @@ async function api(url, options) {
async function fetchChecked(url, options) {
recordDebug('fetch.request', { url, method: options?.method || 'GET' });
const response = await fetch(url, options);
recordDebug('fetch.response', { url, status: response.status, ok: response.ok });
recordDebug('fetch.response', {
url,
status: response.status,
ok: response.ok,
contentType: response.headers.get('content-type')
});
if (!response.ok) {
let message = `${response.status} ${response.statusText}`;
const text = await response.text();
try {
message = (await response.json()).error || message;
message = JSON.parse(text).error || message;
} catch {}
recordDebug('fetch.error.body', { url, status: response.status, body: text.slice(0, 2000) });
throw new Error(message);
}
return response;
+2 -2
View File
@@ -1,7 +1,7 @@
<!DOCTYPE PLUGIN [
<!ENTITY name "u-navigator">
<!ENTITY author "michael">
<!ENTITY version "2026.06.23.r006">
<!ENTITY version "2026.06.23.r007">
<!ENTITY package "&name;-&version;.tgz">
]>
<PLUGIN name="&name;" author="&author;" version="&version;" pluginURL="https://git.casaderoll.de/michael/Unraid-Navigator/raw/branch/main/u-navigator.plg">
@@ -14,7 +14,7 @@
<FILE Name="/boot/config/plugins/&name;/&package;">
<URL>https://git.casaderoll.de/michael/Unraid-Navigator/raw/branch/main/packages/&package;</URL>
<MD5>6079415588844c2e4a3f8aa43f949bd4</MD5>
<MD5>c9e2b618f5907747315c5f17e80b132f</MD5>
</FILE>
<FILE Run="/bin/bash">