15
15
* limitations under the License.
16
16
*/
17
17
18
- import { SDK_VERSION } from '@firebase/app-exp' ;
19
- import { AUTH_ERROR_FACTORY , AuthErrorCode } from '../errors' ;
18
+ import { AuthErrorCode , AUTH_ERROR_FACTORY } from '../errors' ;
20
19
import { logError } from './log' ;
21
20
22
21
/**
@@ -25,8 +24,8 @@ import { logError } from './log';
25
24
* @param appName App name for tagging the error
26
25
* @throws FirebaseError
27
26
*/
28
- export function fail ( appName : string ) : never {
29
- throw AUTH_ERROR_FACTORY . create ( AuthErrorCode . INTERNAL_ERROR , { appName } ) ;
27
+ export function fail ( appName : string , errorCode : AuthErrorCode ) : never {
28
+ throw AUTH_ERROR_FACTORY . create ( errorCode , { appName } ) ;
30
29
}
31
30
32
31
/**
@@ -35,22 +34,12 @@ export function fail(appName: string): never {
35
34
* @param assertion
36
35
* @param appName
37
36
*/
38
- export function assert ( assertion : boolean , appName : string ) : asserts assertion {
37
+ export function assert ( assertion : unknown , appName : string , errorCode : AuthErrorCode = AuthErrorCode . INTERNAL_ERROR ) : asserts assertion {
39
38
if ( ! assertion ) {
40
- fail ( appName ) ;
39
+ fail ( appName , errorCode ) ;
41
40
}
42
41
}
43
42
44
- export function assertStringOrUndefined (
45
- assertion : unknown ,
46
- appName : string
47
- ) : asserts assertion is string | undefined {
48
- assert (
49
- typeof assertion === 'string' || typeof assertion === 'undefined' ,
50
- appName
51
- ) ;
52
- }
53
-
54
43
/**
55
44
* Unconditionally fails, throwing an internal error with the given message.
56
45
*
@@ -60,10 +49,10 @@ export function assertStringOrUndefined(
60
49
export function debugFail ( failure : string ) : never {
61
50
// Log the failure in addition to throw an exception, just in case the
62
51
// exception is swallowed.
63
- const message = `AUTH ( ${ SDK_VERSION } ) INTERNAL ASSERTION FAILED: ` + failure ;
52
+ const message = `INTERNAL ASSERTION FAILED: ` + failure ;
64
53
logError ( message ) ;
65
54
66
- // NOTE: We don't use FirestoreError here because these are internal failures
55
+ // NOTE: We don't use FirebaseError here because these are internal failures
67
56
// that cannot be handled by the user. (Also it would create a circular
68
57
// dependency between the error and assert modules which doesn't work.)
69
58
throw new Error ( message ) ;
0 commit comments