KI-AGENT: Leere JSON Requests in der Mobile App korrigieren
This commit is contained in:
@@ -313,14 +313,15 @@ async function parseJson(response: Response): Promise<unknown> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function apiRequest<T>(path: string, options: RequestOptions = {}): Promise<T> {
|
export async function apiRequest<T>(path: string, options: RequestOptions = {}): Promise<T> {
|
||||||
|
const hasJsonBody = options.body !== undefined;
|
||||||
const response = await fetch(buildUrl(path), {
|
const response = await fetch(buildUrl(path), {
|
||||||
method: options.method || 'GET',
|
method: options.method || 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
Accept: 'application/json',
|
Accept: 'application/json',
|
||||||
'Content-Type': 'application/json',
|
...(hasJsonBody ? { 'Content-Type': 'application/json' } : {}),
|
||||||
...(options.token ? { Authorization: `Bearer ${options.token}` } : {}),
|
...(options.token ? { Authorization: `Bearer ${options.token}` } : {}),
|
||||||
},
|
},
|
||||||
body: options.body ? JSON.stringify(options.body) : undefined,
|
body: hasJsonBody ? JSON.stringify(options.body) : undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
const payload = await parseJson(response);
|
const payload = await parseJson(response);
|
||||||
|
|||||||
Reference in New Issue
Block a user