mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Store: Error handling for setObject (#23650)
* Error handling for setObject to store * Update public/app/core/store.ts Co-Authored-By: kay delaney <45561153+kaydelaney@users.noreply.github.com> * Update public/app/features/explore/RichHistory/RichHistory.tsx Co-Authored-By: kay delaney <45561153+kaydelaney@users.noreply.github.com> * Move setState outside of try-catch block Co-authored-by: kay delaney <45561153+kaydelaney@users.noreply.github.com>
This commit is contained in:
@@ -29,21 +29,19 @@ export class Store {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Returns true when successfully stored
|
||||
setObject(key: string, value: any): boolean {
|
||||
/* Returns true when successfully stored, throws error if not successfully stored */
|
||||
setObject(key: string, value: any) {
|
||||
let json;
|
||||
try {
|
||||
json = JSON.stringify(value);
|
||||
} catch (error) {
|
||||
console.error(`Could not stringify object: ${key}. [${error}]`);
|
||||
return false;
|
||||
throw new Error(`Could not stringify object: ${key}. [${error}]`);
|
||||
}
|
||||
try {
|
||||
this.set(key, json);
|
||||
} catch (error) {
|
||||
// Likely hitting storage quota
|
||||
console.error(`Could not save item in localStorage: ${key}. [${error}]`);
|
||||
return false;
|
||||
throw new Error(`Could not save item in localStorage: ${key}. [${error}]`);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user