Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(stored-searches): try-catch #6271

Merged
merged 2 commits into from
May 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions packages/docs/src/components/docsearch/stored-searches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
try {
localStorage.setItem(key, '');
localStorage.removeItem(key);

return true;
} catch (error) {
return false;
Expand All @@ -26,17 +25,21 @@

return {
setItem(item: TItem[]) {
return window.localStorage.setItem(key, JSON.stringify(item));
try {
return window.localStorage.setItem(key, JSON.stringify(item));
} catch (err) {
//
}
},
getItem(): TItem[] {
let item;
let item = [];
try {
window.localStorage.getItem(key);
item = window.localStorage.getItem(key);

Check failure on line 37 in packages/docs/src/components/docsearch/stored-searches.ts

View workflow job for this annotation

GitHub Actions / Build Docs

Type 'string | null' is not assignable to type 'any[]'.
item = JSON.parse(item);

Check failure on line 38 in packages/docs/src/components/docsearch/stored-searches.ts

View workflow job for this annotation

GitHub Actions / Build Docs

Argument of type 'any[]' is not assignable to parameter of type 'string'.
} catch (err) {
//
}

return item ? JSON.parse(item) : [];
return item;
},
};
}
Expand Down
Loading