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
+8
View File
@@ -16,6 +16,11 @@ class Log
$raw = Request::instance()->getContent(); $raw = Request::instance()->getContent();
$data = json_decode($raw, true) ?: []; $data = json_decode($raw, true) ?: [];
} }
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', [ \app\utils\Logger::error(\app\utils\Logger::CAT_FRONTEND, $data['message'] ?? 'unknown', [
'source' => $data['source'] ?? 'unknown', 'source' => $data['source'] ?? 'unknown',
'type' => $data['type'] ?? 'error', 'type' => $data['type'] ?? 'error',
@@ -28,5 +33,8 @@ class Log
'ip' => Request::instance()->ip(), 'ip' => Request::instance()->ip(),
]); ]);
return json(['status' => 1]); return json(['status' => 1]);
} catch (\Throwable $e) {
return json(['status' => 0, 'error' => $e->getMessage(), 'path' => runtime_path()]);
}
} }
} }