@@ -35,14 +35,17 @@ export function useQaTabs() {
3535 const locale = params . locale as string ;
3636 const localeKey = resolveLocale ( locale ) ;
3737
38- const pageFromUrl = Number ( searchParams . get ( 'page' ) || 1 ) ;
38+ const rawPage = searchParams . get ( 'page' ) ;
39+ const pageFromUrl = rawPage ? Number ( rawPage ) : 1 ;
40+ const safePageFromUrl =
41+ Number . isFinite ( pageFromUrl ) && pageFromUrl > 0 ? pageFromUrl : 1 ;
3942 const categoryFromUrl = searchParams . get ( 'category' ) || DEFAULT_CATEGORY ;
4043 const searchFromUrl = searchParams . get ( 'search' ) || '' ;
4144
4245 const [ active , setActive ] = useState < CategorySlug > (
4346 isCategorySlug ( categoryFromUrl ) ? categoryFromUrl : DEFAULT_CATEGORY
4447 ) ;
45- const [ currentPage , setCurrentPage ] = useState ( pageFromUrl ) ;
48+ const [ currentPage , setCurrentPage ] = useState ( safePageFromUrl ) ;
4649 const [ searchQuery , setSearchQuery ] = useState ( searchFromUrl ) ;
4750 const [ debouncedSearch , setDebouncedSearch ] = useState ( searchFromUrl ) ;
4851 const [ items , setItems ] = useState < QuestionEntry [ ] > ( [ ] ) ;
@@ -101,6 +104,10 @@ export function useQaTabs() {
101104 `/api/questions/${ active } ?page=${ currentPage } &limit=10&locale=${ locale } ${ searchParam } `
102105 ) ;
103106
107+ if ( ! res . ok ) {
108+ throw new Error ( `Failed to load questions: ${ res . status } ` ) ;
109+ }
110+
104111 const data : PaginatedResponse < QuestionApiItem > = await res . json ( ) ;
105112
106113 setItems (
0 commit comments