* Dispatch a request * * @param {String|Object} configOrUrl The config specific for this request (merged with this.defaults) * @param {?Object} config * * @returns {Promise} The Promise to be fulfilled
(configOrUrl, config)
| 37 | * @returns {Promise} The Promise to be fulfilled |
| 38 | */ |
| 39 | async request(configOrUrl, config) { |
| 40 | try { |
| 41 | return await this._request(configOrUrl, config); |
| 42 | } catch (err) { |
| 43 | if (err instanceof Error) { |
| 44 | let dummy = {}; |
| 45 | |
| 46 | Error.captureStackTrace ? Error.captureStackTrace(dummy) : (dummy = new Error()); |
| 47 | |
| 48 | // slice off the Error: ... line |
| 49 | const stack = (() => { |
| 50 | if (!dummy.stack) { |
| 51 | return ''; |
| 52 | } |
| 53 | |
| 54 | const firstNewlineIndex = dummy.stack.indexOf('\n'); |
| 55 | |
| 56 | return firstNewlineIndex === -1 ? '' : dummy.stack.slice(firstNewlineIndex + 1); |
| 57 | })(); |
| 58 | try { |
| 59 | if (!err.stack) { |
| 60 | err.stack = stack; |
| 61 | // match without the 2 top stack lines |
| 62 | } else if (stack) { |
| 63 | const firstNewlineIndex = stack.indexOf('\n'); |
| 64 | const secondNewlineIndex = |
| 65 | firstNewlineIndex === -1 ? -1 : stack.indexOf('\n', firstNewlineIndex + 1); |
| 66 | const stackWithoutTwoTopLines = |
| 67 | secondNewlineIndex === -1 ? '' : stack.slice(secondNewlineIndex + 1); |
| 68 | |
| 69 | if (!String(err.stack).endsWith(stackWithoutTwoTopLines)) { |
| 70 | err.stack += '\n' + stack; |
| 71 | } |
| 72 | } |
| 73 | } catch (e) { |
| 74 | // ignore the case where "stack" is an un-writable property |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | throw err; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | _request(configOrUrl, config) { |
| 83 | /*eslint no-param-reassign:0*/ |