{"record":{"id":"71cd3201ab0acbbf","repo":"diegosouzapw/OmniRoute","slug":"trae-exchangetoken-response-was-not-json","errorCode":null,"errorMessage":"Trae ExchangeToken: response was not JSON","messagePattern":"Trae ExchangeToken: response was not JSON","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"open-sse/executors/trae.ts","lineNumber":460,"sourceCode":"    const clientId =\n      (psd.clientId as string) || resolvePublicCred(\"trae_id\", \"TRAE_OAUTH_CLIENT_ID\");\n    const url = `${host}/cloudide/api/v3/trae/oauth/ExchangeToken`;\n    const body = { ClientID: clientId, RefreshToken: refreshToken, ClientSecret: \"-\", UserID: \"\" };\n\n    const res = await fetch(url, {\n      method: \"POST\",\n      headers: { \"Content-Type\": \"application/json\" },\n      body: JSON.stringify(body),\n    });\n    const text = await res.text();\n    if (!res.ok) {\n      throw new Error(`Trae ExchangeToken HTTP ${res.status}: ${text.slice(0, 200)}`);\n    }\n    let parsed;\n    try {\n      parsed = JSON.parse(text);\n    } catch {\n      throw new Error(\"Trae ExchangeToken: response was not JSON\");\n    }\n    const errCode = parsed?.ResponseMetadata?.Error?.Code;\n    if (errCode) {\n      // Surface invalid-refresh to the caller — BaseExecutor.execute swallows the\n      // refresh exception, but the next request will hit 401 and trigger fallback;\n      // we also leave the (stale) accessToken in place so observability shows why.\n      throw new Error(`Trae ExchangeToken error: ${errCode}`);\n    }\n    const result = parsed?.Result;\n    if (!result?.Token) {\n      throw new Error(\"Trae ExchangeToken: response missing Result.Token\");\n    }\n    return {\n      accessToken: result.Token as string,\n      refreshToken: (result.RefreshToken as string) || refreshToken,\n      expiresAt: result.TokenExpireAt\n        ? new Date(Number(result.TokenExpireAt)).toISOString()\n        : undefined,","sourceCodeStart":442,"sourceCodeEnd":478,"githubUrl":"https://github.com/diegosouzapw/OmniRoute/blob/a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d/open-sse/executors/trae.ts#L442-L478","documentation":"Trae ExchangeToken returned HTTP 200 but the body was not parseable JSON, so the token response could not be read. This indicates a gateway/HTML error page or protocol change from the token endpoint rather than a credential problem.","triggerScenarios":"Thrown at open-sse/executors/trae.ts:460 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Log the raw text to detect endpoint changes","Retry once — gateway hiccups are often transient","Treat repeated occurrences as an upstream API regression"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d","analyzedAt":"2026-08-25T18:35:09.898Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}