mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-04-28 11:41:04 +00:00
fix(weixin): add missing iLink headers to QR code login and clean up error output (#3044)
PR #2943 fixed headers in buildHeaders() but the login flow in waitForLogin() still used a hardcoded incomplete header object. Reuse the shared buildHeaders() so all endpoints send consistent iLink-App-Id and iLink-App-ClientVersion headers. Also wrap channel.connect() in startSingle() with a try/catch so configuration errors print a clean message instead of dumping the yargs help text and a stack trace.
This commit is contained in:
parent
760df2c144
commit
98a0f78c4b
3 changed files with 14 additions and 3 deletions
|
|
@ -35,7 +35,7 @@ function randomUin(): string {
|
|||
return btoa(String.fromCharCode(...buf));
|
||||
}
|
||||
|
||||
function buildHeaders(token?: string): Record<string, string> {
|
||||
export function buildHeaders(token?: string): Record<string, string> {
|
||||
const headers: Record<string, string> = {
|
||||
'Content-Type': 'application/json',
|
||||
'X-WECHAT-UIN': randomUin(),
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
* QR code login flow for WeChat iLink Bot.
|
||||
*/
|
||||
|
||||
import { buildHeaders } from './api.js';
|
||||
|
||||
export interface LoginResult {
|
||||
connected: boolean;
|
||||
token?: string;
|
||||
|
|
@ -54,7 +56,7 @@ export async function waitForLogin(params: {
|
|||
const resp = await fetch(
|
||||
`${apiBaseUrl}/ilink/bot/get_qrcode_status?qrcode=${encodeURIComponent(currentQrcodeId)}`,
|
||||
{
|
||||
headers: { 'iLink-App-ClientVersion': '1' },
|
||||
headers: buildHeaders(),
|
||||
signal: controller.signal,
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -183,7 +183,16 @@ async function startSingle(name: string): Promise<void> {
|
|||
const channel = createChannel(name, config, bridge, { router });
|
||||
channels.set(name, channel);
|
||||
registerToolCallDispatch(bridge, router, channels);
|
||||
await channel.connect();
|
||||
|
||||
try {
|
||||
await channel.connect();
|
||||
} catch (err) {
|
||||
writeStderrLine(
|
||||
`Error: ${err instanceof Error ? err.message : String(err)}`,
|
||||
);
|
||||
bridge.stop();
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
writeServiceInfo([name]);
|
||||
writeStdoutLine(`[Channel] "${name}" is running. Press Ctrl+C to stop.`);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue