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 <noreply@anthropic.com>
This commit is contained in:
parent
467d637ccc
commit
289ac0190c
|
|
@ -63,20 +63,30 @@ export class ConfigController {
|
|||
@ApiOperation({ summary: '获取挖矿状态' })
|
||||
async getMiningStatus() {
|
||||
const miningServiceUrl = this.appConfigService.get<string>('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}`,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue