| 130 | const currentFilename = typeof __filename !== 'undefined' ? __filename : undefined |
| 131 | |
| 132 | function appendFetchStackTrace (err, filename) { |
| 133 | if (!err || typeof err !== 'object') { |
| 134 | return |
| 135 | } |
| 136 | |
| 137 | const stack = typeof err.stack === 'string' ? err.stack : '' |
| 138 | const normalizedFilename = filename.replace(/\\/g, '/') |
| 139 | |
| 140 | if (stack && (stack.includes(filename) || stack.includes(normalizedFilename))) { |
| 141 | return |
| 142 | } |
| 143 | |
| 144 | const capture = {} |
| 145 | Error.captureStackTrace(capture, appendFetchStackTrace) |
| 146 | |
| 147 | if (!capture.stack) { |
| 148 | return |
| 149 | } |
| 150 | |
| 151 | const captureLines = capture.stack.split('\n').slice(1).join('\n') |
| 152 | |
| 153 | err.stack = stack ? `${stack}\n${captureLines}` : capture.stack |
| 154 | } |
| 155 | |
| 156 | module.exports.fetch = function fetch (init, options = undefined) { |
| 157 | return fetchImpl(init, options).catch(err => { |