From 289ac0190cdec7929b390d0d3f603b02a928dbdb Mon Sep 17 00:00:00 2001 From: hailin Date: Wed, 14 Jan 2026 04:42:01 -0800 Subject: [PATCH] fix(mining-admin-service): add logging and fix null data handling in getMiningStatus - Add debug logging to trace mining service calls - Return error object instead of null when data is missing - Include error message in response for debugging Co-Authored-By: Claude Opus 4.5 --- .../src/api/controllers/config.controller.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/backend/services/mining-admin-service/src/api/controllers/config.controller.ts b/backend/services/mining-admin-service/src/api/controllers/config.controller.ts index 6beabf34..1d610075 100644 --- a/backend/services/mining-admin-service/src/api/controllers/config.controller.ts +++ b/backend/services/mining-admin-service/src/api/controllers/config.controller.ts @@ -63,20 +63,30 @@ export class ConfigController { @ApiOperation({ summary: '获取挖矿状态' }) async getMiningStatus() { const miningServiceUrl = this.appConfigService.get('MINING_SERVICE_URL', 'http://localhost:3021'); + this.logger.log(`Fetching mining status from ${miningServiceUrl}/api/v2/admin/status`); try { const response = await fetch(`${miningServiceUrl}/api/v2/admin/status`); if (!response.ok) { - throw new Error('Failed to fetch mining status'); + throw new Error(`Failed to fetch mining status: ${response.status}`); } const result = await response.json(); + this.logger.log(`Mining service response: ${JSON.stringify(result)}`); // mining-service 返回 { success, data, timestamp },需要解包 data - return result.data || result; + if (result.data) { + return result.data; + } + // 如果没有 data 字段,返回错误状态 + return { + initialized: false, + isActive: false, + error: 'Invalid response from mining service', + }; } catch (error) { this.logger.error('Failed to get mining status', error); return { initialized: false, isActive: false, - error: 'Unable to connect to mining service', + error: `Unable to connect to mining service: ${error.message}`, }; } }