@@ -12,6 +12,7 @@ import {
1212} from "@/types/pagination" ;
1313import { Project , ProjectOptions , ProjectQueryParams } from "@/types/project" ;
1414import tags from "@/utils/tags" ;
15+ import { safeFetch } from "@/utils/error" ;
1516
1617export async function fetchProjectInfo ( slug : string ) {
1718 return ConfigApi . getProjectInfos ( slug ) . catch ( ( error ) => {
@@ -30,7 +31,16 @@ async function fetchAllProjects(tag?: string): Promise<Project[]> {
3031 offset,
3132 limit : DEFAULT_BIG_PAGE_SIZE ,
3233 } ;
33- const response = await ProjectApi . getProjects ( paginationParams , tag ) ;
34+ const response = await safeFetch (
35+ ( ) => ProjectApi . getProjects ( paginationParams , tag ) ,
36+ "fetchAllProjects" ,
37+ null ,
38+ { paginationParams }
39+ ) ;
40+
41+ if ( response === null ) {
42+ break ;
43+ }
3444
3545 projects = projects . concat ( response . data ) ;
3646 hasMore = response . hasNextPage ;
@@ -41,32 +51,36 @@ async function fetchAllProjects(tag?: string): Promise<Project[]> {
4151}
4252
4353export async function fetchProject ( slug : string ) : Promise < Project | undefined > {
44- const res = await ProjectApi . getProjects ( {
45- slugs : [ slug ] ,
46- } ) . catch ( ( error ) => {
47- console . error ( `Error fetching PROJECT " ${ slug } ":` , error ) ;
48- return undefined ;
49- } ) ;
50-
51- return res ?. data [ 0 ] ;
54+ return safeFetch (
55+ ( ) => ProjectApi . getProjects ( {
56+ slugs : [ slug ] ,
57+ } ) . then ( res => res . data [ 0 ] ) ,
58+ "fetchProject" ,
59+ undefined ,
60+ { slug }
61+ ) ;
5262}
5363
5464export async function fetchProjects (
5565 query : ProjectQueryParams & PaginationQueryParams ,
5666) : Promise < PaginatedCustomResponse < Project > > {
57- return await ProjectApi . getProjects ( query ) . catch ( ( error ) => {
58- console . error ( "Error fetching PROJECTS" , error ) ;
59- return DEFAULT_PAGINATED_RESPONSE ;
60- } ) ;
67+ return safeFetch (
68+ ( ) => ProjectApi . getProjects ( query ) ,
69+ "fetchProjects" ,
70+ DEFAULT_PAGINATED_RESPONSE ,
71+ { query }
72+ ) ;
6173}
6274
6375export async function fetchProjectOptions (
6476 query : ProjectQueryParams ,
6577) : Promise < ProjectOptions > {
66- return await ProjectApi . getProjectOptions ( query ) . catch ( ( error ) => {
67- console . error ( "Error fetching PROJECT OPTIONS" , error ) ;
68- return DEFAULT_PROJECT_OPTIONS ;
69- } ) ;
78+ return safeFetch (
79+ ( ) => ProjectApi . getProjectOptions ( query ) ,
80+ "fetchProjectOptions" ,
81+ DEFAULT_PROJECT_OPTIONS ,
82+ { query }
83+ ) ;
7084}
7185
7286export async function getAllProjects ( ) : Promise < Project [ ] > {
0 commit comments