1
- import { flatten , isError , uniq , trim , sortBy , get , set } from 'lodash' ;
1
+ import { flatten , isError , uniq , trim , sortBy , get , set , attempt } from 'lodash' ;
2
2
import { List , fromJS , Set } from 'immutable' ;
3
3
import * as fuzzy from 'fuzzy' ;
4
4
import {
@@ -515,6 +515,7 @@ export class Backend {
515
515
) ,
516
516
) ;
517
517
const formattedEntries = entries . map ( this . entryWithFormat ( collection ) ) ;
518
+ // todo: find error somewhere here and put it to errors array
518
519
// If this collection has a "filter" property, filter entries accordingly
519
520
const collectionFilter = collection . get ( 'filter' ) ;
520
521
const filteredEntries = collectionFilter
@@ -526,7 +527,7 @@ export class Backend {
526
527
const groupedEntries = groupEntries ( collection , extension , filteredEntries ) ;
527
528
return groupedEntries ;
528
529
}
529
-
530
+ // todo: return object { entries, errors } + change all other processEntries uses to just take entries
530
531
return filteredEntries ;
531
532
}
532
533
@@ -567,10 +568,14 @@ export class Backend {
567
568
cursorType : 'collectionEntries' ,
568
569
collection,
569
570
} ) ;
571
+
570
572
return {
571
573
entries : this . processEntries ( loadedEntries , collection ) ,
572
574
pagination : cursor . meta ?. get ( 'page' ) ,
573
575
cursor,
576
+ errors : [
577
+ 'error found in process entries'
578
+ ]
574
579
} ;
575
580
}
576
581
@@ -594,14 +599,17 @@ export class Backend {
594
599
}
595
600
596
601
const response = await this . listEntries ( collection ) ;
597
- const { entries } = response ;
602
+ const { entries, errors } = response ;
598
603
let { cursor } = response ;
599
604
while ( cursor && cursor . actions ! . includes ( 'next' ) ) {
600
605
const { entries : newEntries , cursor : newCursor } = await this . traverseCursor ( cursor , 'next' ) ;
601
606
entries . push ( ...newEntries ) ;
602
607
cursor = newCursor ;
603
608
}
604
- return entries ;
609
+ return {
610
+ entries,
611
+ errors,
612
+ } ;
605
613
}
606
614
607
615
async search ( collections : Collection [ ] , searchTerm : string ) {
@@ -869,8 +877,12 @@ export class Backend {
869
877
return ( entry : EntryValue ) : EntryValue => {
870
878
const format = resolveFormat ( collection , entry ) ;
871
879
if ( entry && entry . raw !== undefined ) {
872
- const data = ( format && format . fromFile . bind ( format , entry . raw ) ( ) ) || { } ;
873
- if ( isError ( data ) ) console . error ( data ) ;
880
+ const data = ( format && attempt ( format . fromFile . bind ( format , entry . raw ) ) ) || { } ;
881
+ // const data = (format && format.fromFile.bind(format, entry.raw)()) || {};
882
+ if ( isError ( data ) ) {
883
+ entry = Object . assign ( entry , { parseError : data . message } ) ;
884
+ }
885
+
874
886
return Object . assign ( entry , { data : isError ( data ) ? { } : data } ) ;
875
887
}
876
888
return format . fromFile ( entry ) ;
0 commit comments