(key: string, getRemoteValue: GetResponseAsync)
| 53 | } |
| 54 | |
| 55 | protected getAndCacheRemoteValue(key: string, getRemoteValue: GetResponseAsync): Promise<TimeStampedData> { |
| 56 | if (!key) { |
| 57 | throw new Error("key must be a non-empty string, but was: " + key); |
| 58 | } |
| 59 | |
| 60 | if (!getRemoteValue) { |
| 61 | throw new Error("getRemoteValue must be non-undefined"); |
| 62 | } |
| 63 | |
| 64 | return getRemoteValue().then((responsePackage) => { |
| 65 | let setValue: TimeStampedData = this.setTimeStampedValue(key, responsePackage.parsedResponse); |
| 66 | if (!setValue) { |
| 67 | // Fresh data from the remote was unavailable |
| 68 | this.cache.removeKey(key); |
| 69 | } |
| 70 | return Promise.resolve(setValue); |
| 71 | }).catch((error: OneNoteApi.RequestError) => { |
| 72 | // TODO: Don't use OneNoteApi.RequestError |
| 73 | this.cache.removeKey(key); |
| 74 | return Promise.reject(error); |
| 75 | }); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Returns true if the timestamped data is older than the expiry time; false otherwise. |
no test coverage detected