fix(core): update

This commit is contained in:
Philipp Kunz 2022-08-01 17:15:52 +02:00
parent d3d0649b73
commit 5e6f2c6fbf
2 changed files with 9 additions and 5 deletions

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@pushrocks/smartrequest', name: '@pushrocks/smartrequest',
version: '2.0.8', version: '2.0.9',
description: 'dropin replacement for request' description: 'dropin replacement for request'
} }

View File

@ -98,7 +98,7 @@ export let request = async (
responseStreamArg: boolean = false, responseStreamArg: boolean = false,
requestDataFunc: (req: plugins.http.ClientRequest) => void = null requestDataFunc: (req: plugins.http.ClientRequest) => void = null
): Promise<IExtendedIncomingMessage> => { ): Promise<IExtendedIncomingMessage> => {
const done = plugins.smartpromise.defer<any>(); const done = plugins.smartpromise.defer<IExtendedIncomingMessage>();
// merge options // merge options
const defaultOptions: interfaces.ISmartRequestOptions = { const defaultOptions: interfaces.ISmartRequestOptions = {
@ -158,7 +158,7 @@ export let request = async (
// lets perform the actual request // lets perform the actual request
const requestToFire = requestModule.request(optionsArg, async (response) => { const requestToFire = requestModule.request(optionsArg, async (response) => {
if (responseStreamArg) { if (responseStreamArg) {
done.resolve(response); done.resolve(response as IExtendedIncomingMessage);
} else { } else {
const builtResponse = await buildUtf8Response(response, optionsArg.autoJsonParse); const builtResponse = await buildUtf8Response(response, optionsArg.autoJsonParse);
done.resolve(builtResponse); done.resolve(builtResponse);
@ -190,6 +190,10 @@ export let request = async (
requestToFire.destroy(); requestToFire.destroy();
}); });
const result = await done.promise; const response = await done.promise;
return result; response.on('error', (err) => {
console.log(err);
response.destroy();
})
return response;
}; };