feat: Improve CMS health check error reporting and limit connectivity notice display to developer and debug environments.
Some checks failed
Build & Deploy KLZ Cables / 🔍 Prepare Environment (push) Successful in 22s
Build & Deploy KLZ Cables / 🧪 Quality Assurance (push) Successful in 1m32s
Build & Deploy KLZ Cables / 🚀 Deploy (push) Has been cancelled
Build & Deploy KLZ Cables / ⚡ PageSpeed (push) Has been cancelled
Build & Deploy KLZ Cables / 🔔 Notifications (push) Has been cancelled
Build & Deploy KLZ Cables / 🏗️ Build & Push (push) Has been cancelled
Some checks failed
Build & Deploy KLZ Cables / 🔍 Prepare Environment (push) Successful in 22s
Build & Deploy KLZ Cables / 🧪 Quality Assurance (push) Successful in 1m32s
Build & Deploy KLZ Cables / 🚀 Deploy (push) Has been cancelled
Build & Deploy KLZ Cables / ⚡ PageSpeed (push) Has been cancelled
Build & Deploy KLZ Cables / 🔔 Notifications (push) Has been cancelled
Build & Deploy KLZ Cables / 🏗️ Build & Push (push) Has been cancelled
This commit is contained in:
@@ -93,31 +93,49 @@ export async function getProductBySlug(slug: string, locale: string = 'de') {
|
||||
|
||||
export async function checkHealth() {
|
||||
try {
|
||||
await ensureAuthenticated();
|
||||
|
||||
// 1. Basic connectivity check
|
||||
await client.request(readCollections());
|
||||
// 1. Connectivity & Auth Check
|
||||
try {
|
||||
await ensureAuthenticated();
|
||||
await client.request(readCollections());
|
||||
} catch (e: any) {
|
||||
console.error('Directus authentication failed during health check:', e);
|
||||
return {
|
||||
status: 'error',
|
||||
message:
|
||||
'Authentication failed. Check your DIRECTUS_ADMIN_EMAIL and DIRECTUS_ADMIN_PASSWORD.',
|
||||
code: 'AUTH_FAILED',
|
||||
details: e.message,
|
||||
};
|
||||
}
|
||||
|
||||
// 2. Schema check (does the products table exist?)
|
||||
try {
|
||||
await client.request(readItems('products', { limit: 1 }));
|
||||
} catch (e: any) {
|
||||
if (e.message?.includes('does not exist') || e.code === 'INVALID_PAYLOAD') {
|
||||
if (
|
||||
e.message?.includes('does not exist') ||
|
||||
e.code === 'INVALID_PAYLOAD' ||
|
||||
e.status === 404
|
||||
) {
|
||||
return {
|
||||
status: 'error',
|
||||
message: 'The "products" collection is missing. Please sync your data.',
|
||||
message: 'The "products" collection is missing or inaccessible. Please sync your data.',
|
||||
code: 'SCHEMA_MISSING',
|
||||
};
|
||||
}
|
||||
throw e;
|
||||
return {
|
||||
status: 'error',
|
||||
message: `Schema error: ${e.message}`,
|
||||
code: 'SCHEMA_ERROR',
|
||||
};
|
||||
}
|
||||
|
||||
return { status: 'ok', message: 'Directus is reachable and responding.' };
|
||||
} catch (error: any) {
|
||||
console.error('Directus health check failed:', error);
|
||||
console.error('Directus health check failed with unexpected error:', error);
|
||||
return {
|
||||
status: 'error',
|
||||
message: error.message || 'Unknown error',
|
||||
message: error.message || 'An unexpected error occurred while connecting to the CMS.',
|
||||
code: error.code || 'UNKNOWN',
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user