( path: string, query?: Record<string, any>, tags: string[] = ["wordpress"] )
| 49 | |
| 50 | // Core fetch - throws on error (for functions that require data) |
| 51 | async function wordpressFetch<T>( |
| 52 | path: string, |
| 53 | query?: Record<string, any>, |
| 54 | tags: string[] = ["wordpress"] |
| 55 | ): Promise<T> { |
| 56 | if (!baseUrl) { |
| 57 | throw new Error("WordPress URL not configured"); |
| 58 | } |
| 59 | |
| 60 | const url = `${baseUrl}${path}${query ? `?${querystring.stringify(query)}` : ""}`; |
| 61 | |
| 62 | const response = await fetch(url, { |
| 63 | headers: { "User-Agent": USER_AGENT }, |
| 64 | next: { tags, revalidate: CACHE_TTL }, |
| 65 | }); |
| 66 | |
| 67 | if (!response.ok) { |
| 68 | throw new WordPressAPIError( |
| 69 | `WordPress API request failed: ${response.statusText}`, |
| 70 | response.status, |
| 71 | url |
| 72 | ); |
| 73 | } |
| 74 | |
| 75 | return response.json(); |
| 76 | } |
| 77 | |
| 78 | // Graceful fetch - returns fallback when WordPress unavailable or on error |
| 79 | async function wordpressFetchGraceful<T>( |
no outgoing calls
no test coverage detected