| 184 | } |
| 185 | |
| 186 | onResponseError (_controller, err) { |
| 187 | const { res, callback, body, opaque } = this |
| 188 | |
| 189 | if (callback) { |
| 190 | // TODO: Does this need queueMicrotask? |
| 191 | this.callback = null |
| 192 | queueMicrotask(() => { |
| 193 | this.runInAsyncScope(callback, null, err, { opaque }) |
| 194 | }) |
| 195 | } |
| 196 | |
| 197 | if (res) { |
| 198 | this.res = null |
| 199 | // Ensure all queued handlers are invoked before destroying res. |
| 200 | queueMicrotask(() => { |
| 201 | util.destroy(res.on('error', noop), err) |
| 202 | }) |
| 203 | } |
| 204 | |
| 205 | if (body) { |
| 206 | this.body = null |
| 207 | |
| 208 | if (util.isStream(body)) { |
| 209 | body.on('error', noop) |
| 210 | util.destroy(body, err) |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | if (this.removeAbortListener) { |
| 215 | this.removeAbortListener() |
| 216 | this.removeAbortListener = null |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | function request (opts, callback) { |