📚 Improved backend codebase structure & documentation (#123) 🌟
This commit is contained in:
@ -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 => {
|
||||
|
Reference in New Issue
Block a user