fix(Storage): getJson() implementation

This commit is contained in:
Manu Mtz.-Almeida
2016-01-18 15:01:27 +01:00
parent 2d10593dce
commit d7db59edf1

View File

@ -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);