Skip to content

Commit 7aa1156

Browse files
committed
more size optimizations
1 parent 402316c commit 7aa1156

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/index.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,12 @@ function create(defaults) {
142142
* @template T
143143
* @param {string | Options} url
144144
* @param {Options} [config]
145-
* @param {any} [_method]
146-
* @param {any} [_data]
145+
* @param {any} [_method] (internal)
146+
* @param {any} [data] (internal)
147+
* @param {never} [_undefined] (internal)
147148
* @returns {Promise<Response<T>>}
148149
*/
149-
function redaxios(url, config, _method, _data) {
150+
function redaxios(url, config, _method, data, _undefined) {
150151
if (typeof url !== 'string') {
151152
config = url;
152153
url = config.url;
@@ -160,7 +161,7 @@ function create(defaults) {
160161
/** @type {RequestHeaders} */
161162
const customHeaders = {};
162163

163-
let data = _data || options.data;
164+
data = data || options.data;
164165

165166
(options.transformRequest || []).map((f) => {
166167
data = f(data, options.headers) || data;
@@ -199,14 +200,12 @@ function create(defaults) {
199200
method: (_method || options.method || 'get').toUpperCase(),
200201
body: data,
201202
headers: deepMerge(options.headers, customHeaders, true),
202-
credentials: options.withCredentials ? 'include' : 'same-origin'
203+
credentials: options.withCredentials ? 'include' : _undefined
203204
}).then((res) => {
204205
for (const i in res) {
205206
if (typeof res[i] != 'function') response[i] = res[i];
206207
}
207208

208-
const ok = options.validateStatus ? options.validateStatus(res.status) : res.ok;
209-
210209
if (options.responseType == 'stream') {
211210
response.data = res.body;
212211
return response;
@@ -219,7 +218,10 @@ function create(defaults) {
219218
response.data = JSON.parse(data);
220219
})
221220
.catch(Object)
222-
.then(() => (ok ? response : Promise.reject(response)));
221+
.then(() => {
222+
const ok = options.validateStatus ? options.validateStatus(res.status) : res.ok;
223+
return ok ? response : Promise.reject(response);
224+
});
223225
});
224226
}
225227

0 commit comments

Comments
 (0)