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