Add metric_visualization/js/api.js
This commit is contained in:
parent
d421b0c846
commit
6970cc9a15
1 changed files with 37 additions and 0 deletions
37
metric_visualization/js/api.js
Normal file
37
metric_visualization/js/api.js
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
* @module api
|
||||
* @description Kommunikationsmodul für den Abruf von Analyseergebnissen über den /api/analysis Endpunkt.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Führt einen GET-Request an /api/analysis aus und gibt die JSON-Daten zurück.
|
||||
* @async
|
||||
* @function fetchAnalysisData
|
||||
* @returns {Promise<Array<{run_id: string, t_index_visible: number, t_gate_read: number, delta_t: number, warn_rate: number, unknown_rate: number}>>} Analyseergebnisse
|
||||
* @throws {Error} Wenn der Abruf fehlschlägt oder die Antwort kein gültiges JSON ist.
|
||||
*/
|
||||
export async function fetchAnalysisData() {
|
||||
try {
|
||||
const response = await fetch('/api/analysis', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Accept': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`API-Fehler: ${response.status} ${response.statusText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (!Array.isArray(data)) {
|
||||
throw new Error('Ungültiges Antwortformat: Erwartet wird ein JSON-Array');
|
||||
}
|
||||
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Abrufen der Analyseergebnisse:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue