Skip to content

Commit

Permalink
Fix: Check response status before writing d1 backu (#2296)
Browse files Browse the repository at this point in the history
...p download output
  • Loading branch information
Skye-31 committed Nov 28, 2022
1 parent c6d9ae9 commit 7da8f0e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/itchy-tigers-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Fix: check response status of `d1 backup download` command before writing contents to file
5 changes: 5 additions & 0 deletions packages/wrangler/src/d1/backups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ export const DownloadHandler = withConfig<BackupDownloadArgs>(

logger.log(`🌀 Downloading backup ${backupId} from '${name}'`);
const response = await getBackupResponse(accountId, db.uuid, backupId);
if (!response.ok) {
throw new Error(
`Failed to download backup ${backupId} from '${name}' - got ${response.status} from the API`
);
}
logger.log(`🌀 Saving to ${filename}`);
// TODO: stream this once we upgrade to Node18 and can use Writable.fromWeb
const buffer = await response.arrayBuffer();
Expand Down

0 comments on commit 7da8f0e

Please sign in to comment.