347
348
async readResource(resource: ServerResource, oldValue: IUserData | null, collection?: string, headers: IHeaders = {}): Promise<IUserData> {
350
throw new Error('No settings sync store url configured.');
351
}
353
>
const url = joinPath(this.getResourceUrl(this.userDataSyncStoreUrl, collection, resource), 'latest').toString();
354
>
headers = { ...headers };
355
>
// Disable caching as they are cached by synchronisers
356
>
headers['Cache-Control'] = 'no-cache';
357
>
if (oldValue) {
358
headers['If-None-Match'] = oldValue.ref;
359
}
361
>
const context = await this.request(url, { type: 'GET', headers, callSite: 'userDataSync.readResource' }, [304], CancellationToken.None);
362
>
363
>
let userData: IUserData | null = null;
364
>
if (context.res.statusCode === 304) {
365
userData = oldValue;
366
}
368
>
if (userData === null) {
369
>
const ref = context.res.headers['etag'];
370
>
if (!ref) {
371
throw new UserDataSyncStoreError('Server did not return the ref', url, UserDataSyncErrorCode.NoRef, context.res.statusCode, context.res.headers[HEADER_OPERATION_ID]);
372
}
374
>
const content = await asTextOrError(context);
375
>
if (!content && context.res.statusCode === 304) {
376
throw new UserDataSyncStoreError('Empty response', url, UserDataSyncErrorCode.EmptyResponse, context.res.statusCode, context.res.headers[HEADER_OPERATION_ID]);
377
}
379
>
userData = { ref, content };
380
>
}
381
>
382
>
return userData;
383
>
}
384
385
async writeResource(resource: ServerResource, data: string, ref: string | null, collection?: string, headers: IHeaders = {}): Promise<string> {