refactor: dedupe twitch error formatting

This commit is contained in:
Peter Steinberger
2026-04-07 01:04:37 +01:00
parent 782247b423
commit 999d88d13d
6 changed files with 14 additions and 10 deletions

View File

@@ -4,6 +4,7 @@
* Handles tool-based actions for Twitch, such as sending messages.
*/
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
import { resolveTwitchAccountContext } from "./config.js";
import { twitchOutbound } from "./outbound.js";
import type { ChannelMessageActionAdapter, ChannelMessageActionContext } from "./types.js";
@@ -167,7 +168,7 @@ export const twitchMessageActions: ChannelMessageActionAdapter = {
details: { ok: true },
};
} catch (error) {
const errorMsg = error instanceof Error ? error.message : String(error);
const errorMsg = formatErrorMessage(error);
return errorResponse(errorMsg);
}
},

View File

@@ -6,6 +6,7 @@
*/
import type { MarkdownTableMode, OpenClawConfig } from "openclaw/plugin-sdk/config-runtime";
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
import type { ReplyPayload } from "../api.js";
import { createChannelReplyPipeline } from "../api.js";
import { checkTwitchAccessControl } from "./access-control.js";
@@ -221,7 +222,7 @@ export async function monitorTwitchProvider(
accountId,
);
} catch (error) {
const errorMsg = error instanceof Error ? error.message : String(error);
const errorMsg = formatErrorMessage(error);
runtime.error?.(`Failed to connect: ${errorMsg}`);
throw error;
}

View File

@@ -1,5 +1,6 @@
import { StaticAuthProvider } from "@twurple/auth";
import { ChatClient } from "@twurple/chat";
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
import type { BaseProbeResult } from "../runtime-api.js";
import type { TwitchAccountConfig } from "./types.js";
import { normalizeToken } from "./utils/twitch.js";
@@ -102,7 +103,7 @@ export async function probeTwitch(
} catch (error) {
return {
ok: false,
error: error instanceof Error ? error.message : String(error),
error: formatErrorMessage(error),
username: account.username,
channel: account.channel,
elapsedMs: Date.now() - started,

View File

@@ -7,6 +7,7 @@
import { ApiClient } from "@twurple/api";
import { StaticAuthProvider } from "@twurple/auth";
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
import type { ChannelResolveKind, ChannelResolveResult } from "./types.js";
import type { ChannelLogSink, TwitchAccountConfig } from "./types.js";
import { normalizeToken } from "./utils/twitch.js";
@@ -123,7 +124,7 @@ export async function resolveTwitchTargets(
}
}
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
const errorMessage = formatErrorMessage(error);
results.push({
input,
resolved: false,

View File

@@ -5,6 +5,7 @@
* They support dependency injection via the `deps` parameter for testability.
*/
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
import type { OpenClawConfig } from "../runtime-api.js";
import { getClientManager as getRegistryClientManager } from "./client-manager-registry.js";
import { resolveTwitchAccountContext } from "./config.js";
@@ -127,7 +128,7 @@ export async function sendMessageTwitchInternal(
messageId: result.messageId ?? generateMessageId(),
};
} catch (error) {
const errorMsg = error instanceof Error ? error.message : String(error);
const errorMsg = formatErrorMessage(error);
logger.error(`Failed to send message: ${errorMsg}`);
return {
ok: false,

View File

@@ -1,5 +1,6 @@
import { RefreshingAuthProvider, StaticAuthProvider } from "@twurple/auth";
import { ChatClient, LogLevel } from "@twurple/chat";
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
import type { OpenClawConfig } from "../runtime-api.js";
import { resolveTwitchToken } from "./token.js";
import type { ChannelLogSink, TwitchAccountConfig, TwitchChatMessage } from "./types.js";
@@ -45,7 +46,7 @@ export class TwitchClientManager {
})
.catch((err) => {
this.logger.error(
`Failed to add user to RefreshingAuthProvider: ${err instanceof Error ? err.message : String(err)}`,
`Failed to add user to RefreshingAuthProvider: ${formatErrorMessage(err)}`,
);
});
@@ -250,12 +251,10 @@ export class TwitchClientManager {
return { ok: true, messageId };
} catch (error) {
this.logger.error(
`Failed to send message: ${error instanceof Error ? error.message : String(error)}`,
);
this.logger.error(`Failed to send message: ${formatErrorMessage(error)}`);
return {
ok: false,
error: error instanceof Error ? error.message : String(error),
error: formatErrorMessage(error),
};
}
}