Unverified Commit 7b0846f1 authored by Robert Knight's avatar Robert Knight Committed by GitHub

Merge pull request #2164 from hypothesis/sentry-fetch-errors

Make fetch exceptions consistent and filter them from Sentry
parents 61f44ff4 299106f8
......@@ -136,6 +136,12 @@ function createAPICall(
body: data ? JSON.stringify(stripInternalProperties(data)) : null,
headers,
method: descriptor.method,
}).catch(() => {
// Re-throw Fetch errors such that they all "look the same" (different
// browsers throw different Errors on Fetch failure). This allows
// Fetch failures to be either handled in particular ways higher up
// or for them to be ignored in error reporting (see `sentry` config).
throw new Error(`Fetch operation failed for URL '${url}'`);
});
})
.then(response => {
......
......@@ -175,7 +175,8 @@ describe('sidebar.services.api', function () {
// Network error
status: null,
body: 'Service unreachable.',
expectedMessage: 'Service unreachable.',
expectedMessage:
"Fetch operation failed for URL 'https://example.com/api/profile'",
},
{
// Request failed with an error given in the JSON body
......
......@@ -51,6 +51,8 @@ export function init(config) {
Sentry.init({
dsn: config.dsn,
environment: config.environment,
// Do not log Fetch failures to avoid inundating with unhandled fetch exceptions
ignoreErrors: ['Fetch operation failed'],
release: '__VERSION__', // replaced by versionify
whitelistUrls,
......
......@@ -75,6 +75,20 @@ describe('sidebar/util/sentry', () => {
);
});
it('configures Sentry to ignore Errors with matching the text "Fetch operation failed"', () => {
sentry.init({
dsn: 'test-dsn',
environment: 'dev',
});
assert.calledWith(
fakeSentry.init,
sinon.match({
ignoreErrors: ['Fetch operation failed'],
})
);
});
it('disables the URL whitelist if `document.currentScript` is inaccessible', () => {
fakeDocumentCurrentScript.get(() => null);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment