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