diegosouzapw/OmniRoute · error · Error
Trae ExchangeToken error
Error message
Trae ExchangeToken error: ${errCode} What it means
The Trae ExchangeToken response parsed successfully but its ResponseMetadata.Error.Code was set, meaning the token exchange was explicitly rejected (e.g. invalid or expired refresh token). Throwing surfaces invalid-refresh to the caller so fallback can trigger on the next 401.
Solutions
- Map the error code: invalid refresh tokens require user re-auth, transient codes can retry
- Keep the stale accessToken in place for observability
- Classify terminal vs recoverable codes like other connection errors
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at open-sse/executors/trae.ts:467 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25).
Data as JSON: /api/errors/3b84a7c50f3b6a18.
Report an issue: GitHub.
Appendix: source
Thrown at open-sse/executors/trae.ts:467
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
});
const text = await res.text();
if (!res.ok) {
throw new Error(`Trae ExchangeToken HTTP ${res.status}: ${text.slice(0, 200)}`);
}
let parsed;
try {
parsed = JSON.parse(text);
} catch {
throw new Error("Trae ExchangeToken: response was not JSON");
}
const errCode = parsed?.ResponseMetadata?.Error?.Code;
if (errCode) {
// Surface invalid-refresh to the caller — BaseExecutor.execute swallows the
// refresh exception, but the next request will hit 401 and trigger fallback;
// we also leave the (stale) accessToken in place so observability shows why.
throw new Error(`Trae ExchangeToken error: ${errCode}`);
}
const result = parsed?.Result;
if (!result?.Token) {
throw new Error("Trae ExchangeToken: response missing Result.Token");
}
return {
accessToken: result.Token as string,
refreshToken: (result.RefreshToken as string) || refreshToken,
expiresAt: result.TokenExpireAt
? new Date(Number(result.TokenExpireAt)).toISOString()
: undefined,
};
}
}
export default TraeExecutor;
View on GitHub (pinned to a179ffed5b)