@@ -240,10 +240,14 @@ export async function getPostById(id: number): Promise<Post> {
240240 return wordpressFetch < Post > ( `/wp-json/wp/v2/posts/${ id } ` ) ;
241241}
242242
243- export async function getPostBySlug ( slug : string ) : Promise < Post > {
244- return wordpressFetch < Post [ ] > ( "/wp-json/wp/v2/posts" , { slug } ) . then (
245- ( posts ) => posts [ 0 ]
246- ) ;
243+ export async function getPostBySlug ( slug : string ) : Promise < Post | undefined > {
244+ try {
245+ const posts = await wordpressFetch < Post [ ] > ( "/wp-json/wp/v2/posts" , { slug } ) ;
246+ return posts [ 0 ] ;
247+ } catch ( error ) {
248+ console . warn ( "WordPress unavailable, post not found" ) ;
249+ return undefined ;
250+ }
247251}
248252
249253export async function getAllCategories ( ) : Promise < Category [ ] > {
@@ -311,10 +315,14 @@ export async function getPageById(id: number): Promise<Page> {
311315 return wordpressFetch < Page > ( `/wp-json/wp/v2/pages/${ id } ` ) ;
312316}
313317
314- export async function getPageBySlug ( slug : string ) : Promise < Page > {
315- return wordpressFetch < Page [ ] > ( "/wp-json/wp/v2/pages" , { slug } ) . then (
316- ( pages ) => pages [ 0 ]
317- ) ;
318+ export async function getPageBySlug ( slug : string ) : Promise < Page | undefined > {
319+ try {
320+ const pages = await wordpressFetch < Page [ ] > ( "/wp-json/wp/v2/pages" , { slug } ) ;
321+ return pages [ 0 ] ;
322+ } catch ( error ) {
323+ console . warn ( "WordPress unavailable, page not found" ) ;
324+ return undefined ;
325+ }
318326}
319327
320328export async function getAllAuthors ( ) : Promise < Author [ ] > {
@@ -366,24 +374,39 @@ export async function getFeaturedMediaById(id: number): Promise<FeaturedMedia> {
366374}
367375
368376export async function searchCategories ( query : string ) : Promise < Category [ ] > {
369- return wordpressFetch < Category [ ] > ( "/wp-json/wp/v2/categories" , {
370- search : query ,
371- per_page : 100 ,
372- } ) ;
377+ try {
378+ return await wordpressFetch < Category [ ] > ( "/wp-json/wp/v2/categories" , {
379+ search : query ,
380+ per_page : 100 ,
381+ } ) ;
382+ } catch ( error ) {
383+ console . warn ( "WordPress unavailable, returning empty categories" ) ;
384+ return [ ] ;
385+ }
373386}
374387
375388export async function searchTags ( query : string ) : Promise < Tag [ ] > {
376- return wordpressFetch < Tag [ ] > ( "/wp-json/wp/v2/tags" , {
377- search : query ,
378- per_page : 100 ,
379- } ) ;
389+ try {
390+ return await wordpressFetch < Tag [ ] > ( "/wp-json/wp/v2/tags" , {
391+ search : query ,
392+ per_page : 100 ,
393+ } ) ;
394+ } catch ( error ) {
395+ console . warn ( "WordPress unavailable, returning empty tags" ) ;
396+ return [ ] ;
397+ }
380398}
381399
382400export async function searchAuthors ( query : string ) : Promise < Author [ ] > {
383- return wordpressFetch < Author [ ] > ( "/wp-json/wp/v2/users" , {
384- search : query ,
385- per_page : 100 ,
386- } ) ;
401+ try {
402+ return await wordpressFetch < Author [ ] > ( "/wp-json/wp/v2/users" , {
403+ search : query ,
404+ per_page : 100 ,
405+ } ) ;
406+ } catch ( error ) {
407+ console . warn ( "WordPress unavailable, returning empty authors" ) ;
408+ return [ ] ;
409+ }
387410}
388411
389412// Function specifically for generateStaticParams - fetches ALL posts
0 commit comments