✨ Add 'request' property
parent
4937cd856c
commit
355e8d09c1
14
index.js
14
index.js
|
@ -33,11 +33,7 @@ export default config => new Promise((resolve, reject) => {
|
|||
console.warn(`Timeout of ${config.timeout}ms rounded to ${timeout}ms`);
|
||||
try {
|
||||
const
|
||||
{
|
||||
status,
|
||||
headers,
|
||||
data
|
||||
} = await (await getClient({
|
||||
request = (await getClient({
|
||||
maxRedirections: config.maxRedirects
|
||||
})).request({
|
||||
url: buildURL(buildFullPath(config.baseURL, config.url), config.params, config.paramsSerializer),
|
||||
|
@ -65,6 +61,11 @@ export default config => new Promise((resolve, reject) => {
|
|||
timeout: timeout / 1000,
|
||||
responseType: http.ResponseType.Binary
|
||||
}),
|
||||
{
|
||||
status,
|
||||
headers,
|
||||
data
|
||||
} = await request,
|
||||
binaryData = data.length && new Uint8Array(data),
|
||||
textData = binaryData && (() => { try { return new TextDecoder().decode(binaryData); } catch {} })(),
|
||||
jsonData = textData && (() => { try { return JSON.parse(textData); } catch {} })();
|
||||
|
@ -79,7 +80,8 @@ export default config => new Promise((resolve, reject) => {
|
|||
status,
|
||||
statusText: ReasonPhrases[StatusCodes[status]],
|
||||
headers,
|
||||
config
|
||||
config,
|
||||
request
|
||||
});
|
||||
}
|
||||
catch(error){
|
||||
|
|
Loading…
Reference in New Issue