| | |
| | | const normalized = this.normalizeEventPayload(errorLike); |
| | | |
| | | if (normalized instanceof Error) { |
| | | return normalized.message || normalized.name || 'unknown-error'; |
| | | return normalized.message || normalized.name || '未知错误'; |
| | | } |
| | | |
| | | if (Array.isArray(normalized)) { |
| | |
| | | .map((item) => this.formatErrorMessage(item)) |
| | | .filter(Boolean); |
| | | |
| | | return parts.length > 0 ? parts.join(' | ') : 'unknown-error'; |
| | | return parts.length > 0 ? parts.join(' | ') : '未知错误'; |
| | | } |
| | | |
| | | if (normalized && typeof normalized === 'object') { |
| | |
| | | } |
| | | |
| | | if (normalized === undefined || normalized === null || normalized === '') { |
| | | return 'unknown-error'; |
| | | return '未知错误'; |
| | | } |
| | | |
| | | return String(normalized); |
| | |
| | | return this.aliyunSdk; |
| | | } |
| | | |
| | | // eslint-disable-next-line global-require |
| | | // 延迟加载 SDK,避免未启用阿里云时引入额外依赖。 |
| | | this.aliyunSdk = require('aliyun-iot-device-sdk'); |
| | | return this.aliyunSdk; |
| | | } |
| | |
| | | try { |
| | | responseBody = JSON.parse(rawText); |
| | | } catch (_error) { |
| | | throw new Error('三元组接口返回不是有效 JSON'); |
| | | throw new Error('三元组接口返回的不是有效 JSON'); |
| | | } |
| | | |
| | | return this.extractTuple(responseBody, deviceId); |
| | |
| | | |
| | | if (context.lastRegisterAttempt > 0 && (now - context.lastRegisterAttempt) < retryMs && context.lastRegisterError) { |
| | | this.logger.warn(`[ALIYUN] 三元组请求冷却中 deviceId=${device.deviceId} retryMs=${retryMs} lastError=${context.lastRegisterError}`); |
| | | throw new Error(`阿里云三元组重试冷却中 ${context.lastRegisterError}`); |
| | | throw new Error(`阿里云三元组重试冷却中: ${context.lastRegisterError}`); |
| | | } |
| | | |
| | | context.lastRegisterAttempt = now; |