MCPcopy
hub / github.com/axios/axios / dispatchRequest

Function dispatchRequest

lib/core/dispatchRequest.js:34–89  ·  view source on GitHub ↗
(config)

Source from the content-addressed store, hash-verified

32 * @returns {Promise} The Promise to be fulfilled
33 */
34export default function dispatchRequest(config) {
35 throwIfCancellationRequested(config);
36
37 config.headers = AxiosHeaders.from(config.headers);
38
39 // Transform request data
40 config.data = transformData.call(config, config.transformRequest);
41
42 if (['post', 'put', 'patch'].indexOf(config.method) !== -1) {
43 config.headers.setContentType('application/x-www-form-urlencoded', false);
44 }
45
46 const adapter = adapters.getAdapter(config.adapter || defaults.adapter, config);
47
48 return adapter(config).then(
49 function onAdapterResolution(response) {
50 throwIfCancellationRequested(config);
51
52 // Expose the current response on config so that transformResponse can
53 // attach it to any AxiosError it throws (e.g. on JSON parse failure).
54 // We clean it up afterwards to avoid polluting the config object.
55 config.response = response;
56 try {
57 response.data = transformData.call(config, config.transformResponse, response);
58 } finally {
59 delete config.response;
60 }
61
62 response.headers = AxiosHeaders.from(response.headers);
63
64 return response;
65 },
66 function onAdapterRejection(reason) {
67 if (!isCancel(reason)) {
68 throwIfCancellationRequested(config);
69
70 // Transform response data
71 if (reason && reason.response) {
72 config.response = reason.response;
73 try {
74 reason.response.data = transformData.call(
75 config,
76 config.transformResponse,
77 reason.response
78 );
79 } finally {
80 delete config.response;
81 }
82 reason.response.headers = AxiosHeaders.from(reason.response.headers);
83 }
84 }
85
86 return Promise.reject(reason);
87 }
88 );
89}

Callers 1

Calls 4

isCancelFunction · 0.85
adapterFunction · 0.50
fromMethod · 0.45

Tested by

no test coverage detected