Skip to content

Commit 45e712d

Browse files
committed
Silently fail on CORS errors
1 parent da44f3b commit 45e712d

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

dist/EacCounter.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ function () {
6262
startDate = moment.unix(1535068800); // Unix timestamp for August 24 2018 (contract creation)
6363

6464
url = "https://api.nomics.com/v1/exchange-rates/history?key=".concat(apiKey, "&currency=ETH&start=").concat(startDate.toISOString());
65-
_context2.next = 4;
65+
_context2.prev = 2;
66+
_context2.next = 5;
6667
return fetch(url).then(
6768
/*#__PURE__*/
6869
function () {
6970
var _ref = (0, _asyncToGenerator2.default)(
7071
/*#__PURE__*/
7172
_regenerator.default.mark(function _callee(resp) {
72-
var response;
7373
return _regenerator.default.wrap(function _callee$(_context) {
7474
while (1) {
7575
switch (_context.prev = _context.next) {
@@ -78,10 +78,9 @@ function () {
7878
return resp.json();
7979

8080
case 2:
81-
response = _context.sent;
82-
return _context.abrupt("return", response);
81+
return _context.abrupt("return", _context.sent);
8382

84-
case 4:
83+
case 3:
8584
case "end":
8685
return _context.stop();
8786
}
@@ -94,17 +93,27 @@ function () {
9493
};
9594
}());
9695

97-
case 4:
96+
case 5:
9897
ethToUsdAtTimestampValues = _context2.sent;
98+
_context2.next = 12;
99+
break;
100+
101+
case 8:
102+
_context2.prev = 8;
103+
_context2.t0 = _context2["catch"](2);
104+
console.log('Unable to fetch the amount of transferred USD.');
105+
return _context2.abrupt("return");
106+
107+
case 12:
99108
this.ethToUsdAtTimestampValues = ethToUsdAtTimestampValues;
100109
this._canFetchUSD = true;
101110

102-
case 7:
111+
case 14:
103112
case "end":
104113
return _context2.stop();
105114
}
106115
}
107-
}, _callee2, this);
116+
}, _callee2, this, [[2, 8]]);
108117
}));
109118

110119
return function enableUSDFetching(_x) {

src/EacCounter.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ class EacCounter {
1515

1616
const url = `https://api.nomics.com/v1/exchange-rates/history?key=${apiKey}&currency=ETH&start=${startDate.toISOString()}`;
1717

18-
const ethToUsdAtTimestampValues = await fetch(url).then(async (resp) => {
19-
const response = await resp.json();
20-
return response;
21-
});
18+
let ethToUsdAtTimestampValues;
19+
20+
try {
21+
ethToUsdAtTimestampValues = await fetch(url).then(async (resp) => await resp.json());
22+
} catch (e) {
23+
console.log('Unable to fetch the amount of transferred USD.');
24+
return;
25+
}
2226

2327
this.ethToUsdAtTimestampValues = ethToUsdAtTimestampValues;
2428
this._canFetchUSD = true;

0 commit comments

Comments
 (0)