fix: add timeout and error handling to loadMemberships

Every other cloud RPC call goes through sunCloudAwait (12s timeout),
but loadMemberships() (which resolves which workspace to open right
after login, showing "Загружаю рабочую базу...") called client.rpc/
.from directly with no timeout and no catch. A single slow or dropped
request left the auth gate stuck on that message forever instead of
surfacing a retryable error - there's already a "Проверить ещё раз"
button wired to reloadMemberships(), but nothing ever told the user
they needed to press it.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
pavlov346346-source 2026-09-12 15:50:04 +03:00
parent 571f8e199d
commit 09d54682c2

View File

@ -2982,17 +2982,17 @@ window.SUN_LEGACY_CATALOG_V175=[{"id":"1","name":"Фуршетный бокс
membershipsLoading=true;
try{
let rows=[];
const rpc=await client.rpc('sun_my_workspaces');
const rpc=await sunCloudAwait(client.rpc('sun_my_workspaces'),'Загрузка рабочей базы');
if(!rpc.error&&Array.isArray(rpc.data)){
rows=rpc.data.map(x=>({workspace_id:x.id,name:x.name,role:x.role,display_name:x.display_name,is_active:x.is_active,permissions:x.permissions}));
}else{
// Compatibility fallback for an older server schema.
const direct=await client.from('sun_workspace_members').select('workspace_id,role,display_name,is_active,permissions').eq('user_id',session.user.id);
const direct=await sunCloudAwait(client.from('sun_workspace_members').select('workspace_id,role,display_name,is_active,permissions').eq('user_id',session.user.id),'Загрузка рабочей базы');
if(direct.error)throw rpc.error||direct.error;
const active=(direct.data||[]).filter(x=>x.is_active!==false);
if(active.length){
const ids=active.map(x=>x.workspace_id), names={};
const w=await client.from('sun_workspaces').select('id,name').in('id',ids);if(w.error)throw w.error;(w.data||[]).forEach(x=>names[x.id]=x.name);
const w=await sunCloudAwait(client.from('sun_workspaces').select('id,name').in('id',ids),'Загрузка рабочей базы');if(w.error)throw w.error;(w.data||[]).forEach(x=>names[x.id]=x.name);
rows=active.map(x=>({...x,name:names[x.workspace_id]||'Рабочая база'}));
}
}
@ -3005,6 +3005,10 @@ window.SUN_LEGACY_CATALOG_V175=[{"id":"1","name":"Фуршетный бокс
if(switched.changed)return true;
try{window.dispatchEvent(new CustomEvent('sun:cloud-permissions-changed',{detail:{workspace:clone(workspace),user:clone(session.user)}}));}catch(_){}
return false;
}catch(error){
membershipsLoaded=true;
setStatus('error',error?.message||'Не удалось загрузить рабочую базу.');
return false;
}finally{membershipsLoading=false;}
}