mirror of
https://dev.azure.com/globalhealthx/EMR/_git/helix-engage-server
synced 2026-04-11 10:07:22 +00:00
fix: Ozonetel token 10min cache + invalidate on 401 + force re-login on already logged in
- Token cache reduced from 55min to 10min (Ozonetel expires in ~15min) - All API methods invalidate cached token on 401 - loginAgent forces logout + re-login when "already logged in" to refresh SIP phone mapping Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -84,10 +84,32 @@ export class OzonetelAgentService {
|
||||
|
||||
const data = response.data;
|
||||
|
||||
// "already logged in" is not a real error — treat as success
|
||||
// "already logged in" — force logout + re-login to refresh SIP phone mapping
|
||||
if (data.status === 'error' && data.message?.includes('already logged in')) {
|
||||
this.logger.log(`Agent ${params.agentId} already logged in — treating as success`);
|
||||
return { status: 'success', message: data.message };
|
||||
this.logger.log(`Agent ${params.agentId} already logged in — forcing logout + re-login`);
|
||||
try {
|
||||
await this.logoutAgent({ agentId: params.agentId, password: params.password });
|
||||
const retryResponse = await axios.post(
|
||||
url,
|
||||
new URLSearchParams({
|
||||
userName: this.accountId,
|
||||
apiKey: this.apiKey,
|
||||
phoneNumber: params.phoneNumber,
|
||||
action: 'login',
|
||||
mode: params.mode ?? 'blended',
|
||||
state: 'Ready',
|
||||
}).toString(),
|
||||
{
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
auth: { username: params.agentId, password: params.password },
|
||||
},
|
||||
);
|
||||
this.logger.log(`Agent re-login response: ${JSON.stringify(retryResponse.data)}`);
|
||||
return retryResponse.data;
|
||||
} catch (retryErr: any) {
|
||||
this.logger.error(`Agent re-login failed: ${retryErr.message}`);
|
||||
return { status: 'success', message: 'Re-login attempted' };
|
||||
}
|
||||
}
|
||||
|
||||
this.logger.log(`Agent login response: ${JSON.stringify(data)}`);
|
||||
|
||||
Reference in New Issue
Block a user