UNPKG

rollbar

Version:

Effortlessly track and debug errors in your JavaScript applications with Rollbar. This package includes advanced error tracking features and an intuitive interface to help you identify and fix issues more quickly.

62 lines (54 loc) 1.42 kB
import logger from '../../logger.js'; import * as _ from '../../utility.js'; function makeFetchRequest({ accessToken, url, method, payload, headers, callback, timeout, }) { var controller; var timeoutId; if (_.isFiniteNumber(timeout)) { controller = new AbortController(); timeoutId = setTimeout(function () { controller.abort(); }, timeout); } headers = { 'Content-Type': 'application/json', 'X-Rollbar-Access-Token': accessToken, signal: controller && controller.signal, ...headers, }; fetch(url, { method, headers, body: payload, }) .then(function (response) { if (timeoutId) clearTimeout(timeoutId); const respHeaders = response.headers; const isItemRoute = url.endsWith('/api/1/item/'); const headers = isItemRoute ? { 'Rollbar-Replay-Enabled': respHeaders.get('Rollbar-Replay-Enabled'), 'Rollbar-Replay-RateLimit-Remaining': respHeaders.get( 'Rollbar-Replay-RateLimit-Remaining', ), 'Rollbar-Replay-RateLimit-Reset': respHeaders.get( 'Rollbar-Replay-RateLimit-Reset', ), } : {}; const json = response.json(); callback(null, json, headers); }) .catch(function (error) { logger.error(error.message); callback(error); }); } export default makeFetchRequest;