Skip to content

Commit 5fbcaba

Browse files
NhienLamrenkelvin
authored and
renkelvin
committed
Change _fail to use AuthErrorCode.INTERNAL_ERROR and pass in error me… (#7038)
* Change _fail to use AuthErrorCode.INTERNAL_ERROR and pass in error messsage * Add changeset
1 parent d72b97c commit 5fbcaba

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

.changeset/tough-taxis-travel.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.INTERNAL_ERROR and pass in error message.

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

+20-18
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,26 @@ 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+
311331
context('with network issues', () => {
312332
afterEach(mockFetch.tearDown);
313333

@@ -345,24 +365,6 @@ describe('api/_performApiRequest', () => {
345365
expect(clock.clearTimeout).to.have.been.called;
346366
clock.restore();
347367
});
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).to.be.rejectedWith(
362-
FirebaseError,
363-
'auth/network-request-failed'
364-
);
365-
});
366368
});
367369

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

packages/auth/src/api/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export async function _performFetchWithErrorHandling<V>(
198198
if (e instanceof FirebaseError) {
199199
throw e;
200200
}
201-
_fail(auth, AuthErrorCode.NETWORK_REQUEST_FAILED);
201+
_fail(auth, AuthErrorCode.INTERNAL_ERROR, { 'message': String(e) });
202202
}
203203
}
204204

0 commit comments

Comments
 (0)