mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-04-17 22:27:26 +00:00
16 lines
390 B
JavaScript
16 lines
390 B
JavaScript
// Utility functions for JavaScript runtime
|
|
|
|
function logWithReq(req, message) {
|
|
let reqPath = req.url || 'unknown path';
|
|
console.log(`[${req.method} ${reqPath}] ${message}`);
|
|
}
|
|
|
|
function safeJsonParse(str, defaultValue = null) {
|
|
try {
|
|
return JSON.parse(str);
|
|
} catch (e) {
|
|
console.error('JSON parse error:', e.message);
|
|
return defaultValue;
|
|
}
|
|
}
|