Auth fixes, show correct cost each value on pos
This commit is contained in:
@@ -22,6 +22,7 @@ router.get('/', async (req, res) => {
|
||||
console.log(`[OPERATIONS-METRICS] Getting DB connection...`);
|
||||
const { connection, release } = await getDbConnection();
|
||||
console.log(`[OPERATIONS-METRICS] DB connection obtained in ${Date.now() - startTime}ms`);
|
||||
try {
|
||||
|
||||
const { whereClause, params, dateRange } = getTimeRangeConditions(timeRange, startDate, endDate);
|
||||
|
||||
@@ -370,29 +371,26 @@ router.get('/', async (req, res) => {
|
||||
trend,
|
||||
};
|
||||
|
||||
return { response, release };
|
||||
return response;
|
||||
} finally {
|
||||
// Always release the connection regardless of who wins Promise.race.
|
||||
// If the timeout wins, this IIFE keeps running until MySQL responds; this
|
||||
// finally ensures the connection still returns to the pool.
|
||||
release();
|
||||
}
|
||||
};
|
||||
|
||||
let result;
|
||||
try {
|
||||
result = await Promise.race([mainOperation(), timeoutPromise]);
|
||||
} catch (error) {
|
||||
if (error.message.includes('timeout')) {
|
||||
console.log(`[OPERATIONS-METRICS] Request timed out in ${Date.now() - startTime}ms`);
|
||||
throw error;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
const { response, release } = result;
|
||||
|
||||
if (release) release();
|
||||
const response = await Promise.race([mainOperation(), timeoutPromise]);
|
||||
|
||||
console.log(`[OPERATIONS-METRICS] Request completed in ${Date.now() - startTime}ms`);
|
||||
res.json(response);
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error in /operations-metrics:', error);
|
||||
if (error.message.includes('timeout')) {
|
||||
console.log(`[OPERATIONS-METRICS] Request timed out in ${Date.now() - startTime}ms`);
|
||||
} else {
|
||||
console.error('Error in /operations-metrics:', error);
|
||||
}
|
||||
console.log(`[OPERATIONS-METRICS] Request failed in ${Date.now() - startTime}ms`);
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user