Skip to content

Change _fail to use NETWORK_REQUEST_FAILED #7125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sixty-buckets-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/auth': patch
---

Modify \_fail to use AuthErrorCode.NETWORK_REQUEST_FAILED
40 changes: 20 additions & 20 deletions packages/auth/src/api/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,26 +308,6 @@ describe('api/_performApiRequest', () => {
});
});

context('with non-Firebase Errors', () => {
afterEach(mockFetch.tearDown);

it('should handle non-FirebaseErrors', async () => {
mockFetch.setUpWithOverride(() => {
return new Promise<never>((_, reject) => reject(new Error('error')));
});
const promise = _performApiRequest<typeof request, never>(
auth,
HttpMethod.POST,
Endpoint.SIGN_UP,
request
);
await expect(promise).to.be.rejectedWith(
FirebaseError,
'auth/internal-error'
);
});
});

context('with network issues', () => {
afterEach(mockFetch.tearDown);

Expand Down Expand Up @@ -365,6 +345,26 @@ describe('api/_performApiRequest', () => {
expect(clock.clearTimeout).to.have.been.called;
clock.restore();
});

it('should handle network failure', async () => {
mockFetch.setUpWithOverride(() => {
return new Promise<never>((_, reject) =>
reject(new Error('network error'))
);
});
const promise = _performApiRequest<typeof request, never>(
auth,
HttpMethod.POST,
Endpoint.SIGN_UP,
request
);
await expect(promise)
.to.be.rejectedWith(FirebaseError, 'auth/network-request-failed')
.eventually.with.nested.property(
'customData.message',
'Error: network error'
);
});
});

context('edgcase error mapping', () => {
Expand Down
5 changes: 4 additions & 1 deletion packages/auth/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ export async function _performFetchWithErrorHandling<V>(
if (e instanceof FirebaseError) {
throw e;
}
_fail(auth, AuthErrorCode.INTERNAL_ERROR, { 'message': String(e) });
// Changing this to a different error code will log user out when there is a network error
// because we treat any error other than NETWORK_REQUEST_FAILED as token is invalid.
// https://github.com/firebase/firebase-js-sdk/blob/4fbc73610d70be4e0852e7de63a39cb7897e8546/packages/auth/src/core/auth/auth_impl.ts#L309-L316
_fail(auth, AuthErrorCode.NETWORK_REQUEST_FAILED, { 'message': String(e) });
}
}

Expand Down