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:
@@ -9,8 +9,18 @@ export default function CMSConnectivityNotice() {
|
|||||||
const [isVisible, setIsVisible] = useState(false);
|
const [isVisible, setIsVisible] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Only show in development or if explicitly checking
|
// Only show if we've detected an issue AND we are in a context where we want to see it
|
||||||
const checkCMS = async () => {
|
const checkCMS = async () => {
|
||||||
|
const isDebug = new URLSearchParams(window.location.search).has('cms_debug');
|
||||||
|
const isLocal =
|
||||||
|
window.location.hostname === 'localhost' || window.location.hostname.includes('127.0.0.1');
|
||||||
|
const isStaging =
|
||||||
|
window.location.hostname.includes('staging') ||
|
||||||
|
window.location.hostname.includes('testing');
|
||||||
|
|
||||||
|
// Only proceed with check if it's developer context
|
||||||
|
if (!isLocal && !isStaging && !isDebug) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/health/cms');
|
const response = await fetch('/api/health/cms');
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
@@ -24,10 +34,13 @@ export default function CMSConnectivityNotice() {
|
|||||||
setIsVisible(false);
|
setIsVisible(false);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
// If it's a connection error, only show if we are really debugging
|
||||||
|
if (isDebug || isLocal) {
|
||||||
setStatus('error');
|
setStatus('error');
|
||||||
setErrorMsg('Could not connect to CMS health endpoint');
|
setErrorMsg('Could not connect to CMS health endpoint');
|
||||||
setIsVisible(true);
|
setIsVisible(true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
checkCMS();
|
checkCMS();
|
||||||
|
|||||||
@@ -92,32 +92,50 @@ export async function getProductBySlug(slug: string, locale: string = 'de') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function checkHealth() {
|
export async function checkHealth() {
|
||||||
|
try {
|
||||||
|
// 1. Connectivity & Auth Check
|
||||||
try {
|
try {
|
||||||
await ensureAuthenticated();
|
await ensureAuthenticated();
|
||||||
|
|
||||||
// 1. Basic connectivity check
|
|
||||||
await client.request(readCollections());
|
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?)
|
// 2. Schema check (does the products table exist?)
|
||||||
try {
|
try {
|
||||||
await client.request(readItems('products', { limit: 1 }));
|
await client.request(readItems('products', { limit: 1 }));
|
||||||
} catch (e: any) {
|
} 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 {
|
return {
|
||||||
status: 'error',
|
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',
|
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.' };
|
return { status: 'ok', message: 'Directus is reachable and responding.' };
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('Directus health check failed:', error);
|
console.error('Directus health check failed with unexpected error:', error);
|
||||||
return {
|
return {
|
||||||
status: 'error',
|
status: 'error',
|
||||||
message: error.message || 'Unknown error',
|
message: error.message || 'An unexpected error occurred while connecting to the CMS.',
|
||||||
code: error.code || 'UNKNOWN',
|
code: error.code || 'UNKNOWN',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user