Skip to content

Commit c76b960

Browse files
committed
feat: update FirebasePnvException
1 parent 18f5ecb commit c76b960

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

src/main/java/com/google/firebase/fpnv/FirebasePnvException.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@
1616

1717
package com.google.firebase.fpnv;
1818

19+
import com.google.firebase.ErrorCode;
20+
import com.google.firebase.FirebaseException;
21+
1922
/**
2023
* Generic exception related to Firebase Phone Number Verification.
2124
* Check the error code and message for more
2225
* details.
2326
*/
24-
public class FirebasePnvException extends Exception {
27+
public class FirebasePnvException extends FirebaseException {
2528
private final FirebasePnvErrorCode errorCode;
2629

2730
/**
@@ -37,7 +40,7 @@ public FirebasePnvException(
3740
String message,
3841
Throwable cause
3942
) {
40-
super(message, cause);
43+
super(mapToFirebaseError(errorCode), message, cause);
4144
this.errorCode = errorCode;
4245
}
4346

@@ -57,4 +60,23 @@ public FirebasePnvException(
5760
public FirebasePnvErrorCode getFpnvErrorCode() {
5861
return errorCode;
5962
}
63+
64+
private static ErrorCode mapToFirebaseError(FirebasePnvErrorCode code) {
65+
if (code == null) {
66+
return ErrorCode.INTERNAL;
67+
}
68+
switch (code) {
69+
case INVALID_ARGUMENT:
70+
return ErrorCode.INVALID_ARGUMENT;
71+
case TOKEN_EXPIRED:
72+
case INVALID_TOKEN:
73+
return ErrorCode.UNAUTHENTICATED;
74+
case SERVICE_ERROR:
75+
return ErrorCode.UNAVAILABLE;
76+
case INTERNAL_ERROR:
77+
default:
78+
return ErrorCode.INTERNAL;
79+
}
80+
}
6081
}
82+

0 commit comments

Comments
 (0)