fix(weixin): classify Harness health failures

This commit is contained in:
xmanrui 2026-08-22 04:21:00 +08:00
parent 8eed60bbc9
commit eb21b14f60
9 changed files with 387 additions and 171 deletions

View file

@ -6,6 +6,15 @@ import {
} from '../shared/connection-test.mjs';
const DEFAULT_START_RETRY_DELAYS_MS = Object.freeze([250, 1_000, 3_000]);
const HARNESS_HEALTH_ERROR_CODES = new Set([
'harness-connect-failed',
'harness-timeout',
'harness-access-denied',
'harness-api-not-found',
'harness-http-failed',
'harness-response-invalid',
'harness-rpc-rejected',
]);
function startRetryDelays(value) {
if (value === undefined) return [...DEFAULT_START_RETRY_DELAYS_MS];
@ -32,6 +41,13 @@ function runtimeStartError(code, cause) {
return error;
}
function harnessHealthError(cause) {
const code = HARNESS_HEALTH_ERROR_CODES.has(cause?.code)
? cause.code
: 'harness-check-unknown-failed';
return runtimeStartError(code, cause);
}
function delay(ms, signal) {
return new Promise((resolve, reject) => {
if (signal?.aborted) {
@ -127,7 +143,7 @@ export class WeixinRuntime {
try {
await this.#harness.ensureRunning();
} catch (error) {
throw runtimeStartError('harness-unreachable', error);
throw harnessHealthError(error);
}
this.#status.harnessReachable = true;
await this.#notifyStart();