Commit 138b2498 authored by Lyza Danger Gardner's avatar Lyza Danger Gardner

Re-throw Fetch Errors to make them consistent

Different browsers format Fetch errors differently; give them some
sort of consistency by re-throwing something with a common string.

This will allows us to filter out fetch errors from sentry logging,
as well.
parent cd6c4c31
......@@ -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
......
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