@@ -37,64 +37,81 @@ export const getStaticProps = async ({ params, locale, locales }) => {
37
37
const { technology } = params ;
38
38
const currentLang = locale === 'en' ? 'us' : 'es' ;
39
39
40
- const responseTechs = await fetch ( `${ process . env . BREATHECODE_HOST } /v1/registry/academy/technology?slug=${ technology } &limit=1000&academy=${ WHITE_LABEL_ACADEMY } ` , {
41
- method : 'GET' ,
42
- headers : {
43
- Authorization : `Token ${ process . env . BC_ACADEMY_TOKEN } ` ,
44
- Academy : 4 ,
45
- } ,
46
- } ) ;
47
- const techs = await responseTechs . json ( ) ; // array of objects
48
- const technologyData = techs . results . find ( ( tech ) => tech . slug === technology ) ;
49
-
50
- const qs = parseQuerys ( {
51
- asset_type : 'ARTICLE' ,
52
- visibility : 'PUBLIC' ,
53
- status : 'PUBLISHED' ,
54
- academy : WHITE_LABEL_ACADEMY ,
55
- limit : 1000 ,
56
- technologies : technology ,
57
- } ) ;
58
-
59
- const response = await fetch ( `${ process . env . BREATHECODE_HOST } /v1/registry/asset${ qs } ` ) ;
60
- const exercises = await response . json ( ) ;
61
-
62
- const dataFiltered = exercises ?. results ?. filter (
63
- ( l ) => l ?. category ?. slug === 'how-to' || l ?. category ?. slug === 'como' ,
64
- ) ;
40
+ try {
41
+ const responseTechs = await fetch ( `${ process . env . BREATHECODE_HOST } /v1/registry/academy/technology?slug=${ technology } &limit=1000&academy=${ WHITE_LABEL_ACADEMY } ` , {
42
+ method : 'GET' ,
43
+ headers : {
44
+ Authorization : `Token ${ process . env . BC_ACADEMY_TOKEN } ` ,
45
+ Academy : 4 ,
46
+ } ,
47
+ } ) ;
48
+
49
+ if ( ! responseTechs . ok ) {
50
+ console . error ( `Error fetching technology data: ${ responseTechs . status } ` ) ;
51
+ return { notFound : true } ;
52
+ }
53
+
54
+ const techs = await responseTechs . json ( ) ;
55
+ const technologyData = techs . results ?. find ( ( tech ) => tech . slug === technology ) ;
56
+
57
+ if ( ! technologyData ) {
58
+ return { notFound : true } ;
59
+ }
60
+
61
+ const qs = parseQuerys ( {
62
+ asset_type : 'ARTICLE' ,
63
+ visibility : 'PUBLIC' ,
64
+ status : 'PUBLISHED' ,
65
+ academy : WHITE_LABEL_ACADEMY ,
66
+ limit : 1000 ,
67
+ technologies : technology ,
68
+ } ) ;
69
+
70
+ const response = await fetch ( `${ process . env . BREATHECODE_HOST } /v1/registry/asset${ qs } ` ) ;
71
+
72
+ if ( ! response . ok ) {
73
+ console . error ( `Error fetching articles: ${ response . status } ` ) ;
74
+ return { notFound : true } ;
75
+ }
76
+
77
+ const exercises = await response . json ( ) ;
78
+ const dataFiltered = exercises ?. results ?. filter (
79
+ ( l ) => l ?. category ?. slug === 'how-to' || l ?. category ?. slug === 'como' ,
80
+ ) || [ ] ;
81
+
82
+ if ( dataFiltered . length === 0 ) {
83
+ return { notFound : true } ;
84
+ }
85
+
86
+ const ogUrl = {
87
+ en : `/how-to/technology/${ technology } ` ,
88
+ us : `/how-to/technology/${ technology } ` ,
89
+ } ;
65
90
66
- if ( response . status >= 400 || response . status_code >= 400
67
- || ! technologyData || dataFiltered ?. length === 0 ) {
68
91
return {
69
- notFound : true ,
92
+ props : {
93
+ seo : {
94
+ title : technologyData ?. title ,
95
+ description : '' ,
96
+ image : technologyData ?. icon_url || '' ,
97
+ pathConnector : `/how-to/technology/${ technology } ` ,
98
+ url : ogUrl . en ,
99
+ type : 'website' ,
100
+ card : 'default' ,
101
+ locales,
102
+ locale,
103
+ } ,
104
+ fallback : false ,
105
+ technologyData,
106
+ articles : dataFiltered . filter ( ( project ) => project . lang === currentLang ) . map (
107
+ ( l ) => ( { ...l , difficulty : l . difficulty ?. toLowerCase ( ) || null } ) ,
108
+ ) ,
109
+ } ,
70
110
} ;
111
+ } catch ( error ) {
112
+ console . error ( 'Error in getStaticProps:' , error ) ;
113
+ return { notFound : true } ;
71
114
}
72
-
73
- const ogUrl = {
74
- en : `/how-to/technology/${ technology } ` ,
75
- us : `/how-to/technology/${ technology } ` ,
76
- } ;
77
-
78
- return {
79
- props : {
80
- seo : {
81
- title : technologyData ?. title ,
82
- description : '' ,
83
- image : technologyData ?. icon_url || '' ,
84
- pathConnector : `/how-to/technology/${ technology } ` ,
85
- url : ogUrl . en ,
86
- type : 'website' ,
87
- card : 'default' ,
88
- locales,
89
- locale,
90
- } ,
91
- fallback : false ,
92
- technologyData,
93
- articles : dataFiltered . filter ( ( project ) => project . lang === currentLang ) . map (
94
- ( l ) => ( { ...l , difficulty : l . difficulty ?. toLowerCase ( ) || null } ) ,
95
- ) ,
96
- } ,
97
- } ;
98
115
} ;
99
116
100
117
function ExercisesByTechnology ( { articles, technologyData } ) {
0 commit comments