File tree 3 files changed +43
-4
lines changed 3 files changed +43
-4
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ import { AuthErrorCode } from '../core/errors';
22
22
*/
23
23
export const enum ServerError {
24
24
ADMIN_ONLY_OPERATION = 'ADMIN_ONLY_OPERATION' ,
25
+ BLOCKING_FUNCTION_ERROR_RESPONSE = 'BLOCKING_FUNCTION_ERROR_RESPONSE' ,
25
26
CAPTCHA_CHECK_FAILED = 'CAPTCHA_CHECK_FAILED' ,
26
27
CORS_UNSUPPORTED = 'CORS_UNSUPPORTED' ,
27
28
CREDENTIAL_MISMATCH = 'CREDENTIAL_MISMATCH' ,
@@ -199,5 +200,8 @@ export const SERVER_ERROR_MAP: Partial<ServerErrorMap<ServerError>> = {
199
200
[ ServerError . SECOND_FACTOR_EXISTS ] :
200
201
AuthErrorCode . SECOND_FACTOR_ALREADY_ENROLLED ,
201
202
[ ServerError . SECOND_FACTOR_LIMIT_EXCEEDED ] :
202
- AuthErrorCode . SECOND_FACTOR_LIMIT_EXCEEDED
203
+ AuthErrorCode . SECOND_FACTOR_LIMIT_EXCEEDED ,
204
+
205
+ // Blocking functions related errors.
206
+ [ ServerError . BLOCKING_FUNCTION_ERROR_RESPONSE ] : AuthErrorCode . INTERNAL_ERROR ,
203
207
} ;
Original file line number Diff line number Diff line change @@ -198,6 +198,37 @@ describe('api/_performApiRequest', () => {
198
198
expect ( mock . calls [ 0 ] . request ) . to . eql ( request ) ;
199
199
} ) ;
200
200
201
+ it ( 'should pass through server messages if applicable' , async ( ) => {
202
+ mockEndpoint (
203
+ Endpoint . SIGN_UP ,
204
+ {
205
+ error : {
206
+ code : 400 ,
207
+ message : `${ ServerError . BLOCKING_FUNCTION_ERROR_RESPONSE } : Text text text` ,
208
+ errors : [
209
+ {
210
+ message : 'Text text text'
211
+ }
212
+ ]
213
+ }
214
+ } ,
215
+ 400
216
+ ) ;
217
+ const promise = _performApiRequest < typeof request , typeof serverResponse > (
218
+ auth ,
219
+ HttpMethod . POST ,
220
+ Endpoint . SIGN_UP ,
221
+ request
222
+ ) ;
223
+ let error : FirebaseError ;
224
+ try {
225
+ await promise ;
226
+ } catch ( e ) {
227
+ error = e ;
228
+ }
229
+ expect ( error ! . customData ! . message ) . to . eql ( 'Text text text' ) ;
230
+ } ) ;
231
+
201
232
it ( 'should handle unknown server errors' , async ( ) => {
202
233
const mock = mockEndpoint (
203
234
Endpoint . SIGN_UP ,
Original file line number Diff line number Diff line change @@ -152,7 +152,7 @@ export async function _performFetchWithErrorHandling<V>(
152
152
return json ;
153
153
} else {
154
154
const errorMessage = response . ok ? json . errorMessage : json . error . message ;
155
- const serverErrorCode = errorMessage . split ( ' : ' ) [ 0 ] as ServerError ;
155
+ const [ serverErrorCode , serverErrorMessage ] = errorMessage . split ( ' : ' ) ;
156
156
if ( serverErrorCode === ServerError . FEDERATED_USER_ID_ALREADY_LINKED ) {
157
157
throw _makeTaggedError (
158
158
auth ,
@@ -163,11 +163,15 @@ export async function _performFetchWithErrorHandling<V>(
163
163
throw _makeTaggedError ( auth , AuthErrorCode . EMAIL_EXISTS , json ) ;
164
164
}
165
165
const authError =
166
- errorMap [ serverErrorCode ] ||
166
+ errorMap [ serverErrorCode as ServerError ] ||
167
167
( ( serverErrorCode
168
168
. toLowerCase ( )
169
169
. replace ( / [ _ \s ] + / g, '-' ) as unknown ) as AuthErrorCode ) ;
170
- _fail ( auth , authError ) ;
170
+ if ( serverErrorMessage ) {
171
+ _fail ( auth , authError , { message : serverErrorMessage } ) ;
172
+ } else {
173
+ _fail ( auth , authError ) ;
174
+ }
171
175
}
172
176
} catch ( e ) {
173
177
if ( e instanceof FirebaseError ) {
You can’t perform that action at this time.
0 commit comments