-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core: Handle
net::*
errors as Fetch errors
When making some network requests, we can encounter network errors that are not of the `FetchError` type but are `net` system errors (with error codes starting with `net::`). For example, when switching from one network to another during a file download from the Cozy, the downloading stream will throw an error with the `net::ERR_NETWORKD_CHANGED` code. We want to handle these errors as `FetchError` errors and can do do so by simply looking for the `net::` string in the error message.
- Loading branch information
1 parent
6a567f3
commit cdb7b3e
Showing
4 changed files
with
49 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* eslint-env mocha */ | ||
/* @flow */ | ||
|
||
const should = require('should') | ||
|
||
const remoteErrors = require('../../../core/remote/errors') | ||
|
||
describe('Remote.wrapError', () => { | ||
it('returns an UnreachableCozy error for net::ERR_NETWORKD_CHANGED errors', () => { | ||
const netErr = new Error( | ||
'Failed request, reason: net::ERR_NETWORKD_CHANGED' | ||
) | ||
should(remoteErrors.wrapError(netErr)).have.property( | ||
'code', | ||
remoteErrors.UNREACHABLE_COZY_CODE | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* eslint-env mocha */ | ||
/* @flow */ | ||
|
||
const should = require('should') | ||
|
||
const remoteErrors = require('../../../core/remote/errors') | ||
const syncErrors = require('../../../core/sync/errors') | ||
|
||
describe('Sync.wrapError', () => { | ||
it('returns an UnreachableCozy error for net::ERR_NETWORKD_CHANGED errors', () => { | ||
const netErr = new Error( | ||
'Failed request, reason: net::ERR_NETWORKD_CHANGED' | ||
) | ||
should(syncErrors.wrapError(netErr, 'local')).have.property( | ||
'code', | ||
remoteErrors.UNREACHABLE_COZY_CODE | ||
) | ||
}) | ||
}) |