MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / _executeRequest

Method _executeRequest

lib/helper/REST.js:190–262  ·  view source on GitHub ↗

* Executes axios request * * @param {*} request * * @returns {Promise<*>} response

(request)

Source from the content-addressed store, hash-verified

188 * @returns {Promise<*>} response
189 */
190 async _executeRequest(request) {
191 // Add custom headers. They can be set by amBearerAuthenticated() or haveRequestHeaders()
192 request.headers = { ...this.headers, ...request.headers }
193
194 const _debugRequest = { ...request }
195 this.axios.defaults.timeout = request.timeout || this.options.timeout
196
197 if (this.headers && this.headers.auth) {
198 request.auth = this.headers.auth
199 }
200
201 if (typeof request.data === 'object') {
202 const returnedValue = {}
203 for (const [key, value] of Object.entries(request.data)) {
204 returnedValue[key] = value
205 if (value instanceof Secret) returnedValue[key] = value.getMasked()
206 }
207 _debugRequest.data = returnedValue
208 }
209
210 if (request.data instanceof Secret) {
211 _debugRequest.data = '*****'
212 request.data = typeof request.data === 'object' && !(request.data instanceof Secret) ? { ...request.data.toString() } : request.data.toString()
213 }
214
215 if (typeof request.data === 'string') {
216 if (!request.headers || !request.headers['Content-Type']) {
217 request.headers = { ...request.headers, ...{ 'Content-Type': 'application/x-www-form-urlencoded' } }
218 }
219 }
220
221 const onRequest = this.options.onRequest || this.config.onRequest
222 if (onRequest) {
223 await onRequest(request)
224 }
225
226 try {
227 this.options.prettyPrintJson ? this.debugSection('Request', beautify(JSON.stringify(_debugRequest))) : this.debugSection('Request', JSON.stringify(_debugRequest))
228 } catch (e) {
229 console.log('[REST] Request:', JSON.stringify(_debugRequest))
230 }
231
232 if (this.options.printCurl) {
233 try {
234 this.debugSection('CURL Request', curlize(request))
235 } catch (e) {
236 console.log('[REST] CURL Request:', curlize(request))
237 }
238 }
239
240 let response
241 try {
242 response = await this.axios(request)
243 } catch (err) {
244 if (!err.response) throw err
245 try {
246 this.debugSection('Response', `Response error. Status code: ${err.response.status}`)
247 } catch (e) {

Callers 9

sendGetRequestMethod · 0.95
sendHeadRequestMethod · 0.95
sendPostRequestMethod · 0.95
sendPatchRequestMethod · 0.95
sendPutRequestMethod · 0.95
sendDeleteRequestMethod · 0.95
_requestCreateMethod · 0.80
_requestDeleteMethod · 0.80

Calls 6

beautifyFunction · 0.90
curlizeFunction · 0.85
entriesMethod · 0.80
getMaskedMethod · 0.80
logMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected