0
Fork 0
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:
Fred K. Schott 2024-03-11 12:32:20 -07:00 committed by GitHub
parent d461eb760d
commit 8a23ee530c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 32 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
"@astrojs/db": patch
---
handle success=false response on api endpoints

View file

@ -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`);
}
}

View file

@ -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;
}