feat: add KOMGA_DEBUG environment variable for enhanced logging of Komga requests and responses
This commit is contained in:
3
ENV.md
3
ENV.md
@@ -18,6 +18,9 @@ ADMIN_DEFAULT_PASSWORD=Admin@2025
|
|||||||
# Cache Debug (optional - logs cache operations)
|
# Cache Debug (optional - logs cache operations)
|
||||||
# CACHE_DEBUG=true
|
# CACHE_DEBUG=true
|
||||||
|
|
||||||
|
# Komga Debug (optional - logs all requests to Komga)
|
||||||
|
# KOMGA_DEBUG=true
|
||||||
|
|
||||||
# Komga Request Queue (optional - max concurrent requests to Komga, default: 2)
|
# Komga Request Queue (optional - max concurrent requests to Komga, default: 2)
|
||||||
# KOMGA_MAX_CONCURRENT_REQUESTS=5
|
# KOMGA_MAX_CONCURRENT_REQUESTS=5
|
||||||
|
|
||||||
|
|||||||
@@ -176,6 +176,19 @@ export abstract class BaseApiService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isDebug = process.env.KOMGA_DEBUG === 'true';
|
||||||
|
const startTime = isDebug ? Date.now() : 0;
|
||||||
|
|
||||||
|
if (isDebug) {
|
||||||
|
logger.info({
|
||||||
|
url,
|
||||||
|
method: options.method || 'GET',
|
||||||
|
params,
|
||||||
|
isImage: options.isImage,
|
||||||
|
noJson: options.noJson,
|
||||||
|
}, '🔵 Komga Request');
|
||||||
|
}
|
||||||
|
|
||||||
// Timeout réduit à 15 secondes pour éviter les blocages longs
|
// Timeout réduit à 15 secondes pour éviter les blocages longs
|
||||||
const timeoutMs = 15000;
|
const timeoutMs = 15000;
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
@@ -238,7 +251,24 @@ export abstract class BaseApiService {
|
|||||||
});
|
});
|
||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
|
|
||||||
|
if (isDebug) {
|
||||||
|
const duration = Date.now() - startTime;
|
||||||
|
logger.info({
|
||||||
|
url,
|
||||||
|
status: response.status,
|
||||||
|
duration: `${duration}ms`,
|
||||||
|
ok: response.ok,
|
||||||
|
}, '🟢 Komga Response');
|
||||||
|
}
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
if (isDebug) {
|
||||||
|
logger.error({
|
||||||
|
url,
|
||||||
|
status: response.status,
|
||||||
|
statusText: response.statusText,
|
||||||
|
}, '🔴 Komga Error Response');
|
||||||
|
}
|
||||||
throw new AppError(ERROR_CODES.KOMGA.HTTP_ERROR, {
|
throw new AppError(ERROR_CODES.KOMGA.HTTP_ERROR, {
|
||||||
status: response.status,
|
status: response.status,
|
||||||
statusText: response.statusText,
|
statusText: response.statusText,
|
||||||
@@ -255,6 +285,14 @@ export abstract class BaseApiService {
|
|||||||
|
|
||||||
return response.json();
|
return response.json();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
if (isDebug) {
|
||||||
|
const duration = Date.now() - startTime;
|
||||||
|
logger.error({
|
||||||
|
url,
|
||||||
|
error: error instanceof Error ? error.message : String(error),
|
||||||
|
duration: `${duration}ms`,
|
||||||
|
}, '🔴 Komga Request Failed');
|
||||||
|
}
|
||||||
throw error;
|
throw error;
|
||||||
} finally {
|
} finally {
|
||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
|
|||||||
Reference in New Issue
Block a user