report empty respone with 304 status

This commit is contained in:
Sandeep Somavarapu 2021-07-21 17:39:58 +02:00
parent 8bcc883c6a
commit 3eb7d6735e
No known key found for this signature in database
GPG key ID: 1FED25EC4646638B
3 changed files with 40 additions and 15 deletions

View file

@ -20,6 +20,7 @@ import { URI } from 'vs/base/common/uri';
import { isEqual } from 'vs/base/common/resources';
import { isWeb } from 'vs/base/common/platform';
import { IProductService } from 'vs/platform/product/common/productService';
import { toErrorMessage } from 'vs/base/common/errorMessage';
type AutoSyncClassification = {
sources: { classification: 'SystemMetaData', purpose: 'FeatureInsight', isMeasurement: true };
@ -562,7 +563,11 @@ class AutoSync extends Disposable {
// After syncing, get the manifest if it was not available before
if (this.manifest === null) {
this.manifest = await this.userDataSyncStoreService.manifest(null);
try {
this.manifest = await this.userDataSyncStoreService.manifest(null);
} catch (error) {
throw new UserDataAutoSyncError(toErrorMessage(error), error instanceof UserDataSyncError ? error.code : UserDataSyncErrorCode.Unknown);
}
}
// Update local session id

View file

@ -228,6 +228,7 @@ export const enum UserDataSyncErrorCode {
RequestPathNotEscaped = 'RequestPathNotEscaped',
RequestHeadersNotObject = 'RequestHeadersNotObject',
NoRef = 'NoRef',
EmptyResponse = 'EmptyResponse',
TurnedOff = 'TurnedOff',
SessionExpired = 'SessionExpired',
ServiceChanged = 'ServiceChanged',

View file

@ -285,17 +285,26 @@ export class UserDataSyncStoreClient extends Disposable implements IUserDataSync
const context = await this.request(url, { type: 'GET', headers }, [304], CancellationToken.None);
let userData: IUserData | null = null;
if (context.res.statusCode === 304) {
// There is no new value. Hence return the old value.
return oldValue!;
userData = oldValue;
}
const ref = context.res.headers['etag'];
if (!ref) {
throw new UserDataSyncStoreError('Server did not return the ref', url, UserDataSyncErrorCode.NoRef, context.res.statusCode, context.res.headers[HEADER_OPERATION_ID]);
if (userData === null) {
const ref = context.res.headers['etag'];
if (!ref) {
throw new UserDataSyncStoreError('Server did not return the ref', url, UserDataSyncErrorCode.NoRef, context.res.statusCode, context.res.headers[HEADER_OPERATION_ID]);
}
const content = await asText(context);
if (!content && context.res.statusCode === 304) {
throw new UserDataSyncStoreError('Empty response', url, UserDataSyncErrorCode.EmptyResponse, context.res.statusCode, context.res.headers[HEADER_OPERATION_ID]);
}
userData = { ref, content };
}
const content = await asText(context);
return { ref, content };
return userData;
}
async write(resource: ServerResource, data: string, ref: string | null, headers: IHeaders = {}): Promise<string> {
@ -333,17 +342,27 @@ export class UserDataSyncStoreClient extends Disposable implements IUserDataSync
const context = await this.request(url, { type: 'GET', headers }, [304], CancellationToken.None);
let manifest: IUserDataManifest | null = null;
if (context.res.statusCode === 304) {
// There is no new value. Hence return the old value.
return oldValue!;
manifest = oldValue;
}
const ref = context.res.headers['etag'];
if (!ref) {
throw new UserDataSyncStoreError('Server did not return the ref', url, UserDataSyncErrorCode.NoRef, context.res.statusCode, context.res.headers[HEADER_OPERATION_ID]);
if (!manifest) {
const ref = context.res.headers['etag'];
if (!ref) {
throw new UserDataSyncStoreError('Server did not return the ref', url, UserDataSyncErrorCode.NoRef, context.res.statusCode, context.res.headers[HEADER_OPERATION_ID]);
}
const content = await asText(context);
if (!content && context.res.statusCode === 304) {
throw new UserDataSyncStoreError('Empty response', url, UserDataSyncErrorCode.EmptyResponse, context.res.statusCode, context.res.headers[HEADER_OPERATION_ID]);
}
if (content) {
manifest = { ...JSON.parse(content), ref };
}
}
const manifest = await asJson<Omit<IUserDataManifest, 'ref'>>(context);
const currentSessionId = this.storageService.get(USER_SESSION_ID_KEY, StorageScope.GLOBAL);
if (currentSessionId && manifest && currentSessionId !== manifest.session) {
@ -361,7 +380,7 @@ export class UserDataSyncStoreClient extends Disposable implements IUserDataSync
this.storageService.store(USER_SESSION_ID_KEY, manifest.session, StorageScope.GLOBAL, StorageTarget.MACHINE);
}
return manifest ? { ...manifest, ref } : null;
return manifest;
}
async clear(): Promise<void> {