From b733eab816cea99a5597d6555025f786fb643ba9 Mon Sep 17 00:00:00 2001 From: testadmin Date: Thu, 14 May 2026 11:41:58 +0800 Subject: [PATCH] debug: add error catching to log endpoint --- app/handle/controller/Log.php | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/app/handle/controller/Log.php b/app/handle/controller/Log.php index de61361..e2950c6 100644 --- a/app/handle/controller/Log.php +++ b/app/handle/controller/Log.php @@ -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()]); + } } }