ux: surface safe password edge errors
This commit is contained in:
parent
ab8118a539
commit
3e38792f19
@ -38,11 +38,22 @@
|
|||||||
location.reload();
|
location.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function edgeErrorMessage(result){
|
||||||
|
let message=String(result?.data?.error||'');
|
||||||
|
const context=result?.error?.context;
|
||||||
|
if(!message&&context&&typeof context.clone==='function'){
|
||||||
|
try{
|
||||||
|
const payload=await context.clone().json();
|
||||||
|
message=String(payload?.error||payload?.message||'');
|
||||||
|
}catch(_){}
|
||||||
|
}
|
||||||
|
return message||String(result?.error?.message||'')||'Не удалось изменить пароль.';
|
||||||
|
}
|
||||||
|
|
||||||
async function changePassword(currentPassword,newPassword){
|
async function changePassword(currentPassword,newPassword){
|
||||||
const c=client();if(!c)throw new Error('Сессия пользователя недоступна.');
|
const c=client();if(!c)throw new Error('Сессия пользователя недоступна.');
|
||||||
const result=await c.functions.invoke('caterium-change-password',{body:{current_password:currentPassword,new_password:newPassword}});
|
const result=await c.functions.invoke('caterium-change-password',{body:{current_password:currentPassword,new_password:newPassword}});
|
||||||
const message=result.data?.error||result.error?.message;
|
if(result.error||result.data?.error)throw new Error(await edgeErrorMessage(result));
|
||||||
if(result.error||result.data?.error)throw new Error(message||'Не удалось изменить пароль.');
|
|
||||||
if(result.data?.status!=='changed')throw new Error('Сервер не подтвердил смену пароля.');
|
if(result.data?.status!=='changed')throw new Error('Сервер не подтвердил смену пароля.');
|
||||||
return result.data;
|
return result.data;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user