[Fix] Let setSecureItem propagate storage errors to callers

Remove the silent try/catch from setSecureItem so OAuth hooks can
surface actionable "enable storage" guidance instead of a cryptic
"state lost" error after the round-trip. Add a local try/catch in
ChatUI where the storage write is non-critical.
This commit is contained in:
Yuneng Jiang 2026-04-08 22:13:48 -07:00
parent 4e068718c9
commit df3ddd7a81
No known key found for this signature in database
2 changed files with 7 additions and 7 deletions

View file

@ -348,8 +348,12 @@ const ChatUI: React.FC<ChatUIProps> = ({
]);
useEffect(() => {
setSecureItem("apiKeySource", JSON.stringify(apiKeySource));
setSecureItem("apiKey", apiKey);
try {
setSecureItem("apiKeySource", JSON.stringify(apiKeySource));
setSecureItem("apiKey", apiKey);
} catch {
// Storage full or unavailable — non-critical, skip persisting.
}
sessionStorage.setItem("endpointType", endpointType);
sessionStorage.setItem("selectedTags", JSON.stringify(selectedTags));
sessionStorage.setItem("selectedVectorStores", JSON.stringify(selectedVectorStores));

View file

@ -18,11 +18,7 @@ function decode(encoded: string): string {
}
export function setSecureItem(key: string, value: string): void {
try {
window.sessionStorage.setItem(key, encode(value));
} catch {
// Storage full or unavailable — silently ignore.
}
window.sessionStorage.setItem(key, encode(value));
}
export function getSecureItem(key: string): string | null {