mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 18:01:22 +00:00
fix(coding-agent): prevent crash on OAuth authentication failure (#849)
Detect OAuth authentication failures (expired credentials, offline) and provide helpful error message instead of crashing with generic 'No API key found' error. Co-authored-by: Mario Zechner <badlogicgames@gmail.com>
This commit is contained in:
parent
98fb9f378c
commit
d6bb66a494
2 changed files with 20 additions and 1 deletions
|
|
@ -634,6 +634,14 @@ export class AgentSession {
|
|||
// Validate API key
|
||||
const apiKey = await this._modelRegistry.getApiKey(this.model);
|
||||
if (!apiKey) {
|
||||
const isOAuth = this._modelRegistry.isUsingOAuth(this.model);
|
||||
if (isOAuth) {
|
||||
throw new Error(
|
||||
`Authentication failed for "${this.model.provider}". ` +
|
||||
`Credentials may have expired or network is unavailable. ` +
|
||||
`Run '/login ${this.model.provider}' to re-authenticate.`,
|
||||
);
|
||||
}
|
||||
throw new Error(
|
||||
`No API key found for ${this.model.provider}.\n\n` +
|
||||
`Use /login, set an API key environment variable, or create ${getAuthPath()}`,
|
||||
|
|
|
|||
|
|
@ -641,7 +641,18 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|||
}
|
||||
const key = await modelRegistry.getApiKeyForProvider(resolvedProvider);
|
||||
if (!key) {
|
||||
throw new Error(`No API key found for provider "${resolvedProvider}"`);
|
||||
const isOAuth = modelRegistry.isUsingOAuth(currentModel);
|
||||
if (isOAuth) {
|
||||
throw new Error(
|
||||
`Authentication failed for "${currentModel.provider}". ` +
|
||||
`Credentials may have expired or network is unavailable. ` +
|
||||
`Run '/login ${currentModel.provider}' to re-authenticate.`,
|
||||
);
|
||||
}
|
||||
throw new Error(
|
||||
`No API key found for "${currentModel.provider}". ` +
|
||||
`Set an API key environment variable or run '/login ${currentModel.provider}'.`,
|
||||
);
|
||||
}
|
||||
return key;
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue