fix: don't send Content-Type on PATCH without body (fixes favorite 400)
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -3,7 +3,7 @@ const BASE_URL = '/api'
|
|||||||
export async function apiFetch<T>(path: string, options?: RequestInit): Promise<T> {
|
export async function apiFetch<T>(path: string, options?: RequestInit): Promise<T> {
|
||||||
const method = options?.method?.toUpperCase() || 'GET';
|
const method = options?.method?.toUpperCase() || 'GET';
|
||||||
const headers: Record<string, string> = { ...options?.headers as Record<string, string> };
|
const headers: Record<string, string> = { ...options?.headers as Record<string, string> };
|
||||||
if (['POST', 'PUT', 'PATCH'].includes(method)) {
|
if (['POST', 'PUT', 'PATCH'].includes(method) && options?.body) {
|
||||||
headers['Content-Type'] = headers['Content-Type'] || 'application/json';
|
headers['Content-Type'] = headers['Content-Type'] || 'application/json';
|
||||||
}
|
}
|
||||||
const res = await fetch(`${BASE_URL}${path}`, {
|
const res = await fetch(`${BASE_URL}${path}`, {
|
||||||
|
|||||||
Reference in New Issue
Block a user