📚 Improved backend codebase structure & documentation (#123) 🌟

This commit is contained in:
Till Tomczak
2025-06-20 12:26:29 +02:00
parent 286a70b01f
commit 59f5c543e3
24 changed files with 757 additions and 8 deletions

View File

@ -194,7 +194,7 @@ async function createJobStatusChart() {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
const data = await response.json();
const data = await validateApiResponse(response, 'Job-Status-Chart-Daten');
if (data.error) {
throw new Error(data.error);

View File

@ -117,10 +117,22 @@
// Create request promise
const promise = fetch(url, requestOptions)
.then(response => {
.then(async response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
// Content-Type-Validation für JSON-Responses
const contentType = response.headers.get('content-type');
if (!contentType || !contentType.includes('application/json')) {
const text = await response.text();
// Prüfe auf HTML-Fehlerseiten
if (text.includes('<!DOCTYPE html>') || text.includes('<html')) {
throw new Error(`Server-Fehlerseite erhalten statt JSON-Response`);
}
throw new Error(`Unexpected content-type: ${contentType}`);
}
return response.json();
})
.then(data => {

View File

@ -226,6 +226,16 @@ window.refreshJobs = async function() {
throw new Error(`API-Fehler: ${response.status} ${response.statusText}`);
}
// Content-Type-Validation
const contentType = response.headers.get('content-type');
if (!contentType || !contentType.includes('application/json')) {
const text = await response.text();
if (text.includes('<!DOCTYPE html>') || text.includes('<html')) {
throw new Error(`Server-Fehlerseite erhalten statt JSON-Response`);
}
throw new Error(`Unexpected content-type: ${contentType}`);
}
const data = await response.json();
console.log('📝 API-Response erhalten:', data);

View File

@ -415,7 +415,7 @@ class OptimizationManager {
<div class="w-16 h-16 mx-auto">
<svg class="animate-spin text-blue-500" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 0 1 8-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 0 1 4 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
</svg>
</div>
<div class="absolute -top-1 -right-1 text-2xl animate-bounce">⚡</div>