Skip to content

Commit 5e05f73

Browse files
authored
Merge f3810d8 into a8be6ed
2 parents a8be6ed + f3810d8 commit 5e05f73

File tree

3 files changed

+29
-21
lines changed

3 files changed

+29
-21
lines changed

.changeset/sixty-buckets-repeat.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/auth': patch
3+
---
4+
5+
Modify \_fail to use AuthErrorCode.NETWORK_REQUEST_FAILED

packages/auth/src/api/index.test.ts

+20-20
Original file line numberDiff line numberDiff line change
@@ -308,26 +308,6 @@ describe('api/_performApiRequest', () => {
308308
});
309309
});
310310

311-
context('with non-Firebase Errors', () => {
312-
afterEach(mockFetch.tearDown);
313-
314-
it('should handle non-FirebaseErrors', async () => {
315-
mockFetch.setUpWithOverride(() => {
316-
return new Promise<never>((_, reject) => reject(new Error('error')));
317-
});
318-
const promise = _performApiRequest<typeof request, never>(
319-
auth,
320-
HttpMethod.POST,
321-
Endpoint.SIGN_UP,
322-
request
323-
);
324-
await expect(promise).to.be.rejectedWith(
325-
FirebaseError,
326-
'auth/internal-error'
327-
);
328-
});
329-
});
330-
331311
context('with network issues', () => {
332312
afterEach(mockFetch.tearDown);
333313

@@ -365,6 +345,26 @@ describe('api/_performApiRequest', () => {
365345
expect(clock.clearTimeout).to.have.been.called;
366346
clock.restore();
367347
});
348+
349+
it('should handle network failure', async () => {
350+
mockFetch.setUpWithOverride(() => {
351+
return new Promise<never>((_, reject) =>
352+
reject(new Error('network error'))
353+
);
354+
});
355+
const promise = _performApiRequest<typeof request, never>(
356+
auth,
357+
HttpMethod.POST,
358+
Endpoint.SIGN_UP,
359+
request
360+
);
361+
await expect(promise)
362+
.to.be.rejectedWith(FirebaseError, 'auth/network-request-failed')
363+
.eventually.with.nested.property(
364+
'customData.message',
365+
'Error: network error'
366+
);
367+
});
368368
});
369369

370370
context('edgcase error mapping', () => {

packages/auth/src/api/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,10 @@ export async function _performFetchWithErrorHandling<V>(
181181
if (e instanceof FirebaseError) {
182182
throw e;
183183
}
184-
_fail(auth, AuthErrorCode.INTERNAL_ERROR, { 'message': String(e) });
184+
// Changing this to a different error code will log user out when there is a network error
185+
// because we treat any error other than NETWORK_REQUEST_FAILED as token is invalid.
186+
// https://github.com/firebase/firebase-js-sdk/blob/4fbc73610d70be4e0852e7de63a39cb7897e8546/packages/auth/src/core/auth/auth_impl.ts#L309-L316
187+
_fail(auth, AuthErrorCode.NETWORK_REQUEST_FAILED, { 'message': String(e) });
185188
}
186189
}
187190

0 commit comments

Comments
 (0)