mirror of
https://github.com/withastro/astro.git
synced 2025-01-27 22:19:04 -05:00
add handling for success=false responses (#10387)
This commit is contained in:
parent
d461eb760d
commit
8a23ee530c
3 changed files with 32 additions and 2 deletions
5
.changeset/soft-foxes-grin.md
Normal file
5
.changeset/soft-foxes-grin.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@astrojs/db": patch
|
||||
---
|
||||
|
||||
handle success=false response on api endpoints
|
|
@ -82,11 +82,24 @@ 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),
|
||||
});
|
||||
if (!response.ok) {
|
||||
console.error(`${url.toString()} failed: ${response.status} ${response.statusText}`);
|
||||
console.error(await response.text());
|
||||
throw new Error(`/db/push fetch failed: ${response.status} ${response.statusText}`);
|
||||
}
|
||||
const result = (await response.json()) as
|
||||
| { success: false; }
|
||||
| { success: true; };
|
||||
if (!result.success) {
|
||||
console.error(`${url.toString()} unsuccessful`);
|
||||
console.error(await response.text());
|
||||
throw new Error(`/db/push fetch unsuccessful`);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -432,7 +432,19 @@ export async function getProductionCurrentSnapshot({
|
|||
Authorization: `Bearer ${appToken}`,
|
||||
}),
|
||||
});
|
||||
const result = await response.json();
|
||||
if (!response.ok) {
|
||||
console.error(`${url.toString()} failed: ${response.status} ${response.statusText}`);
|
||||
console.error(await response.text());
|
||||
throw new Error(`/db/schema fetch failed: ${response.status} ${response.statusText}`);
|
||||
}
|
||||
const result = (await response.json()) as
|
||||
| { success: false; data: undefined }
|
||||
| { success: true; data: DBSnapshot };
|
||||
if (!result.success) {
|
||||
console.error(`${url.toString()} unsuccessful`);
|
||||
console.error(await response.text());
|
||||
throw new Error(`/db/schema fetch unsuccessful`);
|
||||
}
|
||||
return result.data;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue