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);
|
return this._strategy.get(key);
|
||||||
}
|
}
|
||||||
getJson(key) {
|
getJson(key) {
|
||||||
try {
|
return this.get(key).then(value => {
|
||||||
return JSON.parse(this._strategy.get(key));
|
try {
|
||||||
} catch(e) {
|
return JSON.parse(value);
|
||||||
console.warn('Storage getJson(): unable to parse value for key', key,' as JSON')
|
} catch (e) {
|
||||||
return null;
|
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) {
|
set(key, value) {
|
||||||
return this._strategy.set(key, value);
|
return this._strategy.set(key, value);
|
||||||
|
Reference in New Issue
Block a user