1
1
import { trexLogger } from '@shared/logger' ;
2
2
import { ParserFn } from '@shared/providers/parser.provider' ;
3
- import { HomeMetadata , ParsedInfo } from '../../models/Metadata' ;
4
3
import _ from 'lodash' ;
5
4
import moment from 'moment' ;
6
- import { HTMLSource } from '../source ' ;
5
+ import { HomeMetadata , ParsedInfo } from '../../models/Metadata ' ;
7
6
import { YTParserConfig } from '../config' ;
7
+ import { HTMLSource } from '../source' ;
8
8
import * as longlabel from './longlabel' ;
9
9
import * as shared from './shared' ;
10
10
import uxlang from './uxlang' ;
@@ -277,7 +277,8 @@ interface SelectedAndSections {
277
277
278
278
function getSelectedAndSections (
279
279
D : Document ,
280
- clientTime : Date
280
+ clientTime : Date ,
281
+ config : YTParserConfig
281
282
) : SelectedAndSections {
282
283
/* selection findings */
283
284
const sectionsWithTitle = _ . compact (
@@ -325,6 +326,7 @@ function getSelectedAndSections(
325
326
}
326
327
throw new Error ( 'No video Info' ) ;
327
328
} catch ( error ) {
329
+ config . errorReporter ?.( error ) ;
328
330
homeLog . debug ( 'Error during video dissect %O' , error ) ;
329
331
const f = e . querySelector ( '#video-title-link' ) ;
330
332
const s = f ? f . getAttribute ( 'aria-label' ) : null ;
@@ -364,7 +366,7 @@ export const processHome: ParserFn<
364
366
HTMLSource ,
365
367
Omit < HomeMetadata , 'id' > ,
366
368
YTParserConfig
367
- > = async ( envelop ) => {
369
+ > = async ( envelop , findings , config ) => {
368
370
const retval : Omit < HomeMetadata , 'id' > = {
369
371
type : 'home' ,
370
372
clientTime : envelop . html . clientTime ,
@@ -380,11 +382,18 @@ export const processHome: ParserFn<
380
382
try {
381
383
const { selected, sections } = getSelectedAndSections (
382
384
envelop . jsdom ,
383
- envelop . html . clientTime
385
+ envelop . html . clientTime ,
386
+ {
387
+ ...config ,
388
+ errorReporter : ( ) => {
389
+ config . errorReporter ?.( envelop ) ;
390
+ } ,
391
+ }
384
392
) ;
385
393
retval . selected = selected ;
386
394
retval . sections = sections ;
387
395
} catch ( e ) {
396
+ config . errorReporter ?.( envelop ) ;
388
397
homeLog . error ( 'Error in processing %s: %s' , envelop . html . href , e . message ) ;
389
398
return null ;
390
399
}
0 commit comments