diff options
author | Minteck <contact@minteck.org> | 2022-06-04 08:51:19 +0200 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-06-04 08:51:19 +0200 |
commit | b22f6770c8bd084d66950655203c61dd701b3d90 (patch) | |
tree | 873d7fb19584ec2709b95cc1ca05a1fc7cfd0fc4 /node_modules/got/source/as-promise.js | |
parent | 383285ecd5292bf9a825e05904955b937de84cc9 (diff) | |
download | equestriadb-b22f6770c8bd084d66950655203c61dd701b3d90.tar.gz equestriadb-b22f6770c8bd084d66950655203c61dd701b3d90.tar.bz2 equestriadb-b22f6770c8bd084d66950655203c61dd701b3d90.zip |
Remove node_modules
Diffstat (limited to 'node_modules/got/source/as-promise.js')
-rw-r--r-- | node_modules/got/source/as-promise.js | 108 |
1 files changed, 0 insertions, 108 deletions
diff --git a/node_modules/got/source/as-promise.js b/node_modules/got/source/as-promise.js deleted file mode 100644 index c502325..0000000 --- a/node_modules/got/source/as-promise.js +++ /dev/null @@ -1,108 +0,0 @@ -'use strict'; -const EventEmitter = require('events'); -const getStream = require('get-stream'); -const is = require('@sindresorhus/is'); -const PCancelable = require('p-cancelable'); -const requestAsEventEmitter = require('./request-as-event-emitter'); -const {HTTPError, ParseError, ReadError} = require('./errors'); -const {options: mergeOptions} = require('./merge'); -const {reNormalize} = require('./normalize-arguments'); - -const asPromise = options => { - const proxy = new EventEmitter(); - - const promise = new PCancelable((resolve, reject, onCancel) => { - const emitter = requestAsEventEmitter(options); - - onCancel(emitter.abort); - - emitter.on('response', async response => { - proxy.emit('response', response); - - const stream = is.null(options.encoding) ? getStream.buffer(response) : getStream(response, options); - - let data; - try { - data = await stream; - } catch (error) { - reject(new ReadError(error, options)); - return; - } - - const limitStatusCode = options.followRedirect ? 299 : 399; - - response.body = data; - - try { - for (const [index, hook] of Object.entries(options.hooks.afterResponse)) { - // eslint-disable-next-line no-await-in-loop - response = await hook(response, updatedOptions => { - updatedOptions = reNormalize(mergeOptions(options, { - ...updatedOptions, - retry: 0, - throwHttpErrors: false - })); - - // Remove any further hooks for that request, because we we'll call them anyway. - // The loop continues. We don't want duplicates (asPromise recursion). - updatedOptions.hooks.afterResponse = options.hooks.afterResponse.slice(0, index); - - return asPromise(updatedOptions); - }); - } - } catch (error) { - reject(error); - return; - } - - const {statusCode} = response; - - if (options.json && response.body) { - try { - response.body = JSON.parse(response.body); - } catch (error) { - if (statusCode >= 200 && statusCode < 300) { - const parseError = new ParseError(error, statusCode, options, data); - Object.defineProperty(parseError, 'response', {value: response}); - reject(parseError); - return; - } - } - } - - if (statusCode !== 304 && (statusCode < 200 || statusCode > limitStatusCode)) { - const error = new HTTPError(response, options); - Object.defineProperty(error, 'response', {value: response}); - if (emitter.retry(error) === false) { - if (options.throwHttpErrors) { - reject(error); - return; - } - - resolve(response); - } - - return; - } - - resolve(response); - }); - - emitter.once('error', reject); - [ - 'request', - 'redirect', - 'uploadProgress', - 'downloadProgress' - ].forEach(event => emitter.on(event, (...args) => proxy.emit(event, ...args))); - }); - - promise.on = (name, fn) => { - proxy.on(name, fn); - return promise; - }; - - return promise; -}; - -module.exports = asPromise; |