Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions apps/studio/src/stores/sync/sync-operations-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -879,14 +879,15 @@ const pollPullBackupThunk = createTypedAsyncThunk(
apiNamespace: 'wpcom/v2',
backup_id: backupId,
} );
const response = syncBackupResponseSchema.parse( rawResponse );
const parseResult = syncBackupResponseSchema.safeParse( rawResponse );
if ( ! parseResult.success ) {
console.error( 'Unexpected backup status response:', rawResponse );
throw new Error( __( 'Unexpected response from server while checking backup status' ) );
}
const response = parseResult.data;

signal.throwIfAborted();

if ( ! response.status ) {
throw new Error( 'Unexpected backup response: missing status' );
}

const hasBackupCompleted = response.status === 'finished';
const downloadUrl = hasBackupCompleted ? response.download_url : null;

Expand Down
8 changes: 7 additions & 1 deletion tools/common/lib/sync/sync-api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from 'fs';
import { Readable } from 'stream';
import { __ } from '@wordpress/i18n';
import { z } from 'zod';
import wpcomFactory from '@studio/common/lib/wpcom-factory';
import wpcomXhrRequest from '@studio/common/lib/wpcom-xhr-request-factory';
Expand Down Expand Up @@ -93,7 +94,12 @@ export async function pollBackupStatus(
backup_id: backupId,
} );

const response = syncBackupResponseSchema.parse( rawResponse );
const parseResult = syncBackupResponseSchema.safeParse( rawResponse );
if ( ! parseResult.success ) {
console.error( 'Unexpected backup status response:', rawResponse );
throw new Error( __( 'Unexpected response from server while checking backup status' ) );
}
const response = parseResult.data;
return {
status: response.status,
downloadUrl: response.download_url ?? null,
Expand Down