Skip to content

Commit

Permalink
docs(stored-searches): try-catch (#6271)
Browse files Browse the repository at this point in the history
* docs(stored-searches): try-catch

* style: lint fmt
  • Loading branch information
PatrickJS committed May 7, 2024
1 parent db03fd4 commit 4ffcc2b
Showing 1 changed file with 9 additions and 6 deletions.
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 @@ function isLocalStorageSupported() {
try {
localStorage.setItem(key, '');
localStorage.removeItem(key);

return true;
} catch (error) {
return false;
Expand All @@ -26,17 +25,21 @@ function createStorage<TItem>(key: string) {

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

0 comments on commit 4ffcc2b

Please sign in to comment.