Skip to content

Commit

Permalink
Change _fail to use AuthErrorCode.INTERNAL_ERROR and pass in error me… (
Browse files Browse the repository at this point in the history
#7038)

* Change _fail to use AuthErrorCode.INTERNAL_ERROR and pass in error messsage

* Add changeset
  • Loading branch information
NhienLam authored and renkelvin committed Mar 2, 2023
1 parent d72b97c commit 5fbcaba
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .changeset/tough-taxis-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/auth': patch
---

Modify \_fail to use AuthErrorCode.INTERNAL_ERROR and pass in error message.
38 changes: 20 additions & 18 deletions packages/auth/src/api/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,26 @@ 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 @@ -345,24 +365,6 @@ 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'
);
});
});

context('edgcase error mapping', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export async function _performFetchWithErrorHandling<V>(
if (e instanceof FirebaseError) {
throw e;
}
_fail(auth, AuthErrorCode.NETWORK_REQUEST_FAILED);
_fail(auth, AuthErrorCode.INTERNAL_ERROR, { 'message': String(e) });
}
}

Expand Down

0 comments on commit 5fbcaba

Please sign in to comment.