Skip to content

Commit

Permalink
add handling for success=false responses
Browse files Browse the repository at this point in the history
  • Loading branch information
FredKSchott committed Mar 11, 2024
1 parent cd5e8d4 commit da04e9b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/soft-foxes-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/db": patch
---

handle success=false response on api endpoints
7 changes: 6 additions & 1 deletion packages/db/src/core/cli/commands/push/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,16 @@ async function pushSchema({
return new Response(null, { status: 200 });
}
const url = new URL('/db/push', getRemoteDatabaseUrl());
return await fetch(url, {
const response = await fetch(url, {
method: 'POST',
headers: new Headers({
Authorization: `Bearer ${appToken}`,
}),
body: JSON.stringify(requestBody),
});
const result = await response.json();
if (!result.success) {
throw new Error(url.toString() + ' failed: ' + JSON.stringify(result));
}
return result;
}
3 changes: 3 additions & 0 deletions packages/db/src/core/cli/migration-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,9 @@ export async function getProductionCurrentSnapshot({
}),
});
const result = await response.json();
if (!result.success) {
throw new Error(url.toString() + ' failed: ' + JSON.stringify(result));
}
return result.data;
}

Expand Down

0 comments on commit da04e9b

Please sign in to comment.