File tree Expand file tree Collapse file tree 3 files changed +22
-9
lines changed Expand file tree Collapse file tree 3 files changed +22
-9
lines changed Original file line number Diff line number Diff line change @@ -43,19 +43,23 @@ class BaseClient {
43
43
// Using Reduce to compute the validity of all extractors
44
44
const allExtractorsValid = await this . extractors . reduce ( async ( curExtractorsValid , curExtractor ) => {
45
45
const { name } = curExtractor . constructor ;
46
-
47
46
if ( curExtractor . validate ) {
48
47
logger . debug ( `Validating ${ name } ` ) ;
49
- const isExtractorValid = await curExtractor . validate ( ) ;
50
- if ( isExtractorValid ) {
51
- logger . debug ( `Extractor ${ name } PASSED CSV validation` ) ;
52
- } else {
53
- logger . warn ( `Extractor ${ name } FAILED CSV validation` ) ;
48
+ try {
49
+ const isExtractorValid = await curExtractor . validate ( ) ;
50
+ if ( isExtractorValid ) {
51
+ logger . debug ( `Extractor ${ name } PASSED CSV validation` ) ;
52
+ } else {
53
+ logger . warn ( `Extractor ${ name } FAILED CSV validation` ) ;
54
+ }
55
+ return ( ( await curExtractorsValid ) && isExtractorValid ) ;
56
+ } catch ( e ) {
57
+ logger . warn ( `Extractor ${ name } could not validate. Encountered the following error: ${ e . message } ` ) ;
58
+ return false ;
54
59
}
55
- return ( curExtractorsValid && isExtractorValid ) ;
56
60
}
57
61
return curExtractorsValid ;
58
- } , true ) ;
62
+ } , Promise . resolve ( true ) ) ;
59
63
60
64
if ( allExtractorsValid ) {
61
65
logger . info ( 'Validation succeeded' ) ;
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ function stringNormalizer(str) {
7
7
8
8
// For translating null/nil-like values into empty strings
9
9
function normalizeEmptyValues ( data , unalterableColumns = [ ] ) {
10
+ logger . debug ( 'Checking for empty CSV values to normalize' ) ;
10
11
const EMPTY_VALUES = [ 'null' , 'nil' ] . map ( stringNormalizer ) ;
11
12
const normalizedUnalterableColumns = unalterableColumns . map ( stringNormalizer ) ;
12
13
// Flag tracking if empty values were normalized or not.
Original file line number Diff line number Diff line change @@ -16,12 +16,20 @@ class CSVURLModule {
16
16
// If data is already cached, this function does nothing
17
17
async fillDataCache ( ) {
18
18
if ( ! this . data ) {
19
- const csvData = await axios . get ( this . url ) . then ( ( res ) => res . data ) ;
19
+ logger . debug ( 'Filling the data cache of CSVURLModule' ) ;
20
+ const csvData = await axios . get ( this . url )
21
+ . then ( ( res ) => res . data )
22
+ . catch ( ( e ) => {
23
+ logger . error ( 'Error occurred when making a connection to this url' ) ;
24
+ throw e ;
25
+ } ) ;
26
+ logger . debug ( 'Web request successful' ) ;
20
27
// Parse then normalize the data
21
28
const parsedData = parse ( csvData , {
22
29
columns : ( header ) => header . map ( ( column ) => stringNormalizer ( column ) ) ,
23
30
bom : true ,
24
31
} ) ;
32
+ logger . debug ( 'CSV Data parsing successful' ) ;
25
33
this . data = normalizeEmptyValues ( parsedData , this . unalterableColumns ) ;
26
34
}
27
35
}
You can’t perform that action at this time.
0 commit comments