-
Notifications
You must be signed in to change notification settings - Fork 875
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not throw from connection.send in Node.js (#5578)
* do not throw from connection.send * Create curvy-peaches-deliver.md * add tests * formatting
- Loading branch information
Showing
6 changed files
with
53 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@firebase/storage": patch | ||
--- | ||
|
||
Do not throw from `connection.send` to enable retries in Node.js. |
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
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,17 @@ | ||
import { expect } from "chai"; | ||
import { SinonFakeXMLHttpRequest, useFakeXMLHttpRequest } from "sinon"; | ||
import { ErrorCode } from "../../src/implementation/connection"; | ||
import { XhrConnection } from "../../src/platform/browser/connection"; | ||
|
||
describe('Connections', () => { | ||
it('XhrConnection.send() should not reject on network errors', async () => { | ||
const fakeXHR = useFakeXMLHttpRequest(); | ||
const connection = new XhrConnection(); | ||
const sendPromise = connection.send('testurl', 'GET'); | ||
// simulate a network error | ||
((connection as any).xhr_ as SinonFakeXMLHttpRequest).error(); | ||
await sendPromise; | ||
expect(connection.getErrorCode()).to.equal(ErrorCode.NETWORK_ERROR); | ||
fakeXHR.restore(); | ||
}); | ||
}); |
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,15 @@ | ||
import { stub } from 'sinon'; | ||
import { expect } from 'chai'; | ||
import { ErrorCode } from '../../src/implementation/connection'; | ||
import { FetchConnection } from '../../src/platform/node/connection'; | ||
|
||
describe('Connections', () => { | ||
it('FetchConnection.send() should not reject on network errors', async () => { | ||
const connection = new FetchConnection(); | ||
|
||
// need the casting here because fetch_ is a private member | ||
stub(connection as any, 'fetch_').rejects(); | ||
await connection.send('testurl', 'GET'); | ||
expect(connection.getErrorCode()).to.equal(ErrorCode.NETWORK_ERROR); | ||
}); | ||
}); |