(resolve, reject)
| 62 | }; |
| 63 | |
| 64 | function makeCallback(resolve, reject) { |
| 65 | return function (response) { |
| 66 | const chunks = []; |
| 67 | response.on('data', chunk => { |
| 68 | chunks.push(chunk); |
| 69 | }); |
| 70 | response.on('end', () => { |
| 71 | const body = Buffer.concat(chunks); |
| 72 | const httpResponse = new HTTPResponse(response, body); |
| 73 | |
| 74 | // Consider <200 && >= 400 as errors |
| 75 | if (httpResponse.status < 200 || httpResponse.status >= 400) { |
| 76 | return reject(httpResponse); |
| 77 | } else { |
| 78 | return resolve(httpResponse); |
| 79 | } |
| 80 | }); |
| 81 | response.on('error', reject); |
| 82 | }; |
| 83 | } |
| 84 | |
| 85 | const encodeBody = function ({ body, headers = {} }) { |
| 86 | if (typeof body !== 'object') { |
no test coverage detected