Improve error messages for missing API keys and HTTP errors
Show clear guidance when provider has no key configured instead of cryptic 401. Add friendly messages for 429/403 errors during streaming. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -1148,6 +1148,16 @@ function setStreaming(on){
|
|||||||
// ── Send Message (SSE Streaming) ──
|
// ── Send Message (SSE Streaming) ──
|
||||||
async function sendMessage(text){
|
async function sendMessage(text){
|
||||||
if(!text||!activeProvider||streaming) return;
|
if(!text||!activeProvider||streaming) return;
|
||||||
|
// Check if provider has an API key
|
||||||
|
if(!activeProvider.api_key){
|
||||||
|
hideWelcome();
|
||||||
|
history.push({role:'user',content:text});
|
||||||
|
addMessage(text,'user',null);
|
||||||
|
addMessage('No API key configured for '+activeProvider.name+'. Click the key/edit icon next to the provider in the sidebar to add your API key, or select a provider that has one.','assistant',{error:true});
|
||||||
|
$('message').value='';
|
||||||
|
$('message').style.height='auto';
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(!currentSessionId) currentSessionId='sess-'+Date.now();
|
if(!currentSessionId) currentSessionId='sess-'+Date.now();
|
||||||
history.push({role:'user',content:text});
|
history.push({role:'user',content:text});
|
||||||
addMessage(text,'user',null);
|
addMessage(text,'user',null);
|
||||||
@@ -1178,8 +1188,12 @@ async function sendMessage(text){
|
|||||||
const chunk=JSON.parse(line.slice(5));
|
const chunk=JSON.parse(line.slice(5));
|
||||||
if(chunk.type==='done'){ streamDone=true; break; }
|
if(chunk.type==='done'){ streamDone=true; break; }
|
||||||
if(chunk.type==='error'){
|
if(chunk.type==='error'){
|
||||||
if(!bubbleEl) bubbleEl=addMessage(chunk.delta,'assistant',{error:true});
|
let errMsg=chunk.delta||'Unknown error';
|
||||||
else bubbleEl.innerHTML+=esc(chunk.delta);
|
if(errMsg.includes('HTTP 401')) errMsg='Authentication failed — the API key for this provider is missing or invalid. Open Settings to configure it.';
|
||||||
|
else if(errMsg.includes('HTTP 429')) errMsg='Rate limited — too many requests. Wait a moment and try again.';
|
||||||
|
else if(errMsg.includes('HTTP 403')) errMsg='Access denied — check your API key and permissions.';
|
||||||
|
if(!bubbleEl) bubbleEl=addMessage(errMsg,'assistant',{error:true});
|
||||||
|
else bubbleEl.innerHTML+=esc(errMsg);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(chunk.type==='delta'){
|
if(chunk.type==='delta'){
|
||||||
|
|||||||
Reference in New Issue
Block a user