debug: add error catching to log endpoint

This commit is contained in:
testadmin
2026-05-14 11:41:58 +08:00
parent df6aa119a0
commit b733eab816
+20 -12
View File
@@ -16,17 +16,25 @@ class Log
$raw = Request::instance()->getContent();
$data = json_decode($raw, true) ?: [];
}
\app\utils\Logger::error(\app\utils\Logger::CAT_FRONTEND, $data['message'] ?? 'unknown', [
'source' => $data['source'] ?? 'unknown',
'type' => $data['type'] ?? 'error',
'stack' => isset($data['stack']) ? substr($data['stack'], 0, 2000) : '',
'file' => $data['file'] ?? '',
'url' => $data['url'] ?? '',
'line' => $data['line'] ?? '',
'col' => $data['col'] ?? '',
'ua' => Request::instance()->header('user-agent', ''),
'ip' => Request::instance()->ip(),
]);
return json(['status' => 1]);
if (empty($data)) {
$raw2 = file_get_contents('php://input');
$data = json_decode($raw2, true) ?: [];
}
try {
\app\utils\Logger::error(\app\utils\Logger::CAT_FRONTEND, $data['message'] ?? 'unknown', [
'source' => $data['source'] ?? 'unknown',
'type' => $data['type'] ?? 'error',
'stack' => isset($data['stack']) ? substr($data['stack'], 0, 2000) : '',
'file' => $data['file'] ?? '',
'url' => $data['url'] ?? '',
'line' => $data['line'] ?? '',
'col' => $data['col'] ?? '',
'ua' => Request::instance()->header('user-agent', ''),
'ip' => Request::instance()->ip(),
]);
return json(['status' => 1]);
} catch (\Throwable $e) {
return json(['status' => 0, 'error' => $e->getMessage(), 'path' => runtime_path()]);
}
}
}