add centralized error handling and improve Google Auth error logging

This commit is contained in:
bobbert committed 2026-02-24 23:23:53 +00:00
1 parent 0ef59ba5d3
commit f6c61ab829
5 files changed
+175 -161

No files matched your search

+30 -21
View File
@@ -42,9 +42,12 @@ async function main() {
console.log('[1] Fetching user info...');
try {
const res = await fetch(USERINFO_URL, { headers });
if (!res.ok) throw new Error(`HTTP ${res.status}: ${await res.text()}`);
const user = await res.json();
console.log(` Authenticated as: ${user.email} (${user.name})\n`);
if (!res.ok) {
console.log(` Failed: HTTP ${res.status}: ${await res.text()}\n`);
} else {
const user = await res.json();
console.log(` Authenticated as: ${user.email} (${user.name})\n`);
}
} catch (err) {
console.log(` Failed: ${err.message}\n`);
}
@@ -57,16 +60,19 @@ async function main() {
headers: { ...headers, 'Content-Type': 'application/json' },
body: JSON.stringify({ pageSize: 10 }),
});
if (!res.ok) throw new Error(`HTTP ${res.status}: ${await res.text()}`);
const data = await res.json();
const items = data.mediaItems || [];
console.log(` Found ${items.length} items`);
items.slice(0, 5).forEach((item, i) => {
console.log(` ${i + 1}. ${item.filename} (${item.mimeType})`);
});
if (items.length > 5) console.log(` ... and ${items.length - 5} more`);
if (data.nextPageToken) console.log(' More pages available');
console.log();
if (!res.ok) {
console.log(` Failed: HTTP ${res.status}: ${await res.text()}\n`);
} else {
const data = await res.json();
const items = data.mediaItems || [];
console.log(` Found ${items.length} items`);
items.slice(0, 5).forEach((item, i) => {
console.log(` ${i + 1}. ${item.filename} (${item.mimeType})`);
});
if (items.length > 5) console.log(` ... and ${items.length - 5} more`);
if (data.nextPageToken) console.log(' More pages available');
console.log();
}
} catch (err) {
console.log(` Failed: ${err.message}\n`);
}
@@ -75,14 +81,17 @@ async function main() {
console.log('[3] Listing albums...');
try {
const res = await fetch(`${API_BASE}/albums?pageSize=10`, { headers });
if (!res.ok) throw new Error(`HTTP ${res.status}: ${await res.text()}`);
const data = await res.json();
const albums = data.albums || [];
console.log(` Found ${albums.length} albums`);
albums.slice(0, 5).forEach((album, i) => {
console.log(` ${i + 1}. "${album.title}" - ${album.mediaItemsCount || 0} items`);
});
console.log();
if (!res.ok) {
console.log(` Failed: HTTP ${res.status}: ${await res.text()}\n`);
} else {
const data = await res.json();
const albums = data.albums || [];
console.log(` Found ${albums.length} albums`);
albums.slice(0, 5).forEach((album, i) => {
console.log(` ${i + 1}. "${album.title}" - ${album.mediaItemsCount || 0} items`);
});
console.log();
}
} catch (err) {
console.log(` Failed: ${err.message}\n`);
}