mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-23 05:58:26 +08:00
fix(Storage): getJson() implementation
This commit is contained in:
@ -20,12 +20,14 @@ export class Storage {
|
||||
return this._strategy.get(key);
|
||||
}
|
||||
getJson(key) {
|
||||
try {
|
||||
return JSON.parse(this._strategy.get(key));
|
||||
} catch(e) {
|
||||
console.warn('Storage getJson(): unable to parse value for key', key,' as JSON')
|
||||
return null;
|
||||
}
|
||||
return this.get(key).then(value => {
|
||||
try {
|
||||
return JSON.parse(value);
|
||||
} catch (e) {
|
||||
console.warn('Storage getJson(): unable to parse value for key', key, ' as JSON');
|
||||
throw e; // rethrowing exception so it can be handled with .catch()
|
||||
}
|
||||
});
|
||||
}
|
||||
set(key, value) {
|
||||
return this._strategy.set(key, value);
|
||||
|
Reference in New Issue
Block a user