@@ -8,6 +8,7 @@ const PassThrough = require('stream').PassThrough;
88const Cookies = require ( './cookies' ) ;
99const packageData = require ( '../../package.json' ) ;
1010const net = require ( 'net' ) ;
11+ const errors = require ( '../errors' ) ;
1112
1213const MAX_REDIRECTS = 5 ;
1314
@@ -76,7 +77,7 @@ function nmfetch(url, options) {
7677 return ;
7778 }
7879 finished = true ;
79- err . type = 'FETCH' ;
80+ err . code = errors . EFETCH ;
8081 err . sourceUrl = url ;
8182 fetchRes . emit ( 'error' , err ) ;
8283 } ) ;
@@ -99,7 +100,7 @@ function nmfetch(url, options) {
99100 return ;
100101 }
101102 finished = true ;
102- E . type = 'FETCH' ;
103+ E . code = errors . EFETCH ;
103104 E . sourceUrl = url ;
104105 fetchRes . emit ( 'error' , E ) ;
105106 return ;
@@ -147,7 +148,7 @@ function nmfetch(url, options) {
147148 } catch ( E ) {
148149 finished = true ;
149150 setImmediate ( ( ) => {
150- E . type = 'FETCH' ;
151+ E . code = errors . EFETCH ;
151152 E . sourceUrl = url ;
152153 fetchRes . emit ( 'error' , E ) ;
153154 } ) ;
@@ -162,7 +163,7 @@ function nmfetch(url, options) {
162163 finished = true ;
163164 req . abort ( ) ;
164165 let err = new Error ( 'Request Timeout' ) ;
165- err . type = 'FETCH' ;
166+ err . code = errors . EFETCH ;
166167 err . sourceUrl = url ;
167168 fetchRes . emit ( 'error' , err ) ;
168169 } ) ;
@@ -173,7 +174,7 @@ function nmfetch(url, options) {
173174 return ;
174175 }
175176 finished = true ;
176- err . type = 'FETCH' ;
177+ err . code = errors . EFETCH ;
177178 err . sourceUrl = url ;
178179 fetchRes . emit ( 'error' , err ) ;
179180 } ) ;
@@ -204,7 +205,7 @@ function nmfetch(url, options) {
204205 if ( options . redirects > options . maxRedirects ) {
205206 finished = true ;
206207 let err = new Error ( 'Maximum redirect count exceeded' ) ;
207- err . type = 'FETCH' ;
208+ err . code = errors . EFETCH ;
208209 err . sourceUrl = url ;
209210 fetchRes . emit ( 'error' , err ) ;
210211 req . abort ( ) ;
@@ -222,7 +223,7 @@ function nmfetch(url, options) {
222223 if ( res . statusCode >= 300 && ! options . allowErrorResponse ) {
223224 finished = true ;
224225 let err = new Error ( 'Invalid status code ' + res . statusCode ) ;
225- err . type = 'FETCH' ;
226+ err . code = errors . EFETCH ;
226227 err . sourceUrl = url ;
227228 fetchRes . emit ( 'error' , err ) ;
228229 req . abort ( ) ;
@@ -234,7 +235,7 @@ function nmfetch(url, options) {
234235 return ;
235236 }
236237 finished = true ;
237- err . type = 'FETCH' ;
238+ err . code = errors . EFETCH ;
238239 err . sourceUrl = url ;
239240 fetchRes . emit ( 'error' , err ) ;
240241 req . abort ( ) ;
@@ -247,7 +248,7 @@ function nmfetch(url, options) {
247248 return ;
248249 }
249250 finished = true ;
250- err . type = 'FETCH' ;
251+ err . code = errors . EFETCH ;
251252 err . sourceUrl = url ;
252253 fetchRes . emit ( 'error' , err ) ;
253254 req . abort ( ) ;
@@ -267,7 +268,7 @@ function nmfetch(url, options) {
267268 }
268269 } catch ( err ) {
269270 finished = true ;
270- err . type = 'FETCH' ;
271+ err . code = errors . EFETCH ;
271272 err . sourceUrl = url ;
272273 fetchRes . emit ( 'error' , err ) ;
273274 return ;
0 commit comments