@@ -28,32 +28,34 @@ export default function ArticleViewsGraph() {
2828 try {
2929 const results = await Promise . all (
3030 pages . map ( async ( page ) => {
31- const response = await fetchPageViewsCount ( {
32- article : page ,
33- project,
34- acess : platform ,
35- agents : agent ,
36- dateType : dateType ?. toLowerCase ( ) ,
37- start : dates . start ,
38- end : dates . end ,
39- } ) ;
31+ try {
32+ const response = await fetchPageViewsCount ( {
33+ article : page ,
34+ project,
35+ acess : platform ,
36+ agents : agent ,
37+ dateType : dateType ?. toLowerCase ( ) ,
38+ start : dates . start ,
39+ end : dates . end ,
40+ } ) ;
4041
41- if ( ! response ?. items ) {
42- throw new Error ( 'Invalid response format' ) ;
43- }
42+ const views = Array . isArray ( response ?. items ) ? response . items : [ ] ;
4443
45- const views = response . items ;
46- const dates = views . map ( ( view ) => {
47- const year = view . timestamp . substring ( 0 , 4 ) ;
48- const month = view . timestamp . substring ( 4 , 6 ) ;
49- const day = view . timestamp . substring ( 6 , 8 ) ;
50- return `${ year } -${ month } -${ day } ` ;
51- } ) ;
52- const counts = views . map ( ( view ) => view . views ) ;
53- return { article : page , dates, counts } ;
44+ const viewDates = views . map ( ( view ) => {
45+ const year = view . timestamp . substring ( 0 , 4 ) ;
46+ const month = view . timestamp . substring ( 4 , 6 ) ;
47+ const day = view . timestamp . substring ( 6 , 8 ) ;
48+ return `${ year } -${ month } -${ day } ` ;
49+ } ) ;
50+ const counts = views . map ( ( view ) => view . views ) ;
51+ return { article : page , dates : viewDates , counts } ;
52+ } catch ( e ) {
53+ return { article : page , dates : [ ] , counts : [ ] } ;
54+ }
5455 } ) ,
5556 ) ;
5657
58+
5759 const combinedDates = [ ...new Set ( results . flatMap ( ( data ) => data . dates ) ) ] . sort ( ) ;
5860 const datasets = results . map ( ( data , index ) => ( {
5961 label : decodeURIComponent ( data . article ) ,
0 commit comments