@@ -66,6 +66,8 @@ export class Fetcher {
66
66
* @param {Object } params.wrapperAd - Previously parsed ad node (Wrapper) related to this fetching.
67
67
* @param {Number } params.maxWrapperDepth - The maximum number of Wrapper that can be fetch
68
68
* @param {Function } params.emitter - The function used to Emit event
69
+ * @emits VASTParser#VAST-resolving
70
+ * @emits VASTParser#VAST-resolved
69
71
* @return {Promise }
70
72
*/
71
73
fetchVAST ( {
@@ -76,46 +78,46 @@ export class Fetcher {
76
78
previousUrl = null ,
77
79
wrapperAd = null ,
78
80
} ) {
79
- return new Promise ( async ( resolve , reject ) => {
81
+ return new Promise ( ( resolve , reject ) => {
80
82
const timeBeforeGet = Date . now ( ) ;
81
83
82
84
// Process url with defined filter
83
85
this . URLTemplateFilters . forEach ( ( filter ) => {
84
86
url = filter ( url ) ;
85
87
} ) ;
86
88
87
- try {
88
- emitter ( 'VAST-resolving' , {
89
- url,
90
- previousUrl,
91
- wrapperDepth,
92
- maxWrapperDepth : maxWrapperDepth ,
93
- timeout : this . fetchingOptions . timeout ,
94
- wrapperAd,
95
- } ) ;
89
+ emitter ( 'VAST-resolving' , {
90
+ url,
91
+ previousUrl,
92
+ wrapperDepth,
93
+ maxWrapperDepth,
94
+ timeout : this . fetchingOptions . timeout ,
95
+ wrapperAd,
96
+ } ) ;
96
97
97
- let data = await this . urlHandler . get ( url , this . fetchingOptions ) ;
98
- const requestDuration = Math . round ( Date . now ( ) - timeBeforeGet ) ;
98
+ this . urlHandler
99
+ . get ( url , this . fetchingOptions )
100
+ . then ( ( data ) => {
101
+ const requestDuration = Math . round ( Date . now ( ) - timeBeforeGet ) ;
99
102
100
- emitter ( 'VAST-resolved' , {
101
- url,
102
- previousUrl,
103
- wrapperDepth,
104
- error : data ?. error || null ,
105
- duration : requestDuration ,
106
- statusCode : data ?. statusCode || null ,
107
- ...data ?. details ,
108
- } ) ;
109
- updateEstimatedBitrate ( data ?. details ?. byteLength , requestDuration ) ;
103
+ emitter ( 'VAST-resolved' , {
104
+ url,
105
+ previousUrl,
106
+ wrapperDepth,
107
+ error : data ?. error || null ,
108
+ duration : requestDuration ,
109
+ statusCode : data ?. statusCode || null ,
110
+ ...data ?. details ,
111
+ } ) ;
112
+ updateEstimatedBitrate ( data ?. details ?. byteLength , requestDuration ) ;
110
113
111
- if ( data . error ) {
112
- reject ( data . error ) ;
113
- } else {
114
- resolve ( data . xml ) ;
115
- }
116
- } catch ( error ) {
117
- reject ( error ) ;
118
- }
114
+ if ( data . error ) {
115
+ reject ( data . error ) ;
116
+ } else {
117
+ resolve ( data . xml ) ;
118
+ }
119
+ } )
120
+ . catch ( ( error ) => reject ( error ) ) ;
119
121
} ) ;
120
122
}
121
123
}
0 commit comments