Add trace_visualization/js/api.js
This commit is contained in:
parent
5b26cc03a4
commit
02507c6712
1 changed files with 43 additions and 0 deletions
43
trace_visualization/js/api.js
Normal file
43
trace_visualization/js/api.js
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
'use strict';
|
||||
|
||||
/**
|
||||
* Sendet GET-Anfrage an /api/get-analysis und gibt geparste JSON-Daten zurück.
|
||||
* @param {Object} [options] - Optionales Filterobjekt { filter: 'idle' | 'load' }
|
||||
* @returns {Promise<Object>} - Promise, das das Analyse-Datenobjekt liefert
|
||||
*/
|
||||
export async function fetchAnalysisData(options = {}) {
|
||||
const endpoint = '/api/get-analysis';
|
||||
const params = new URLSearchParams();
|
||||
|
||||
if (options.filter && (options.filter === 'idle' || options.filter === 'load')) {
|
||||
params.append('filter', options.filter);
|
||||
}
|
||||
|
||||
const url = params.toString() ? `${endpoint}?${params.toString()}` : endpoint;
|
||||
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Accept': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
console.error(`API-Fehler: ${response.status} ${response.statusText}`);
|
||||
throw new Error(`Fehler beim Abrufen der Analyse: ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (!data || typeof data !== 'object' || !Array.isArray(data.runs)) {
|
||||
console.error('Unerwartetes Datenformat von /api/get-analysis:', data);
|
||||
throw new Error('Ungültige Datenstruktur von der API');
|
||||
}
|
||||
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Abruf der Analysedaten:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue