Skip to content

Commit

Permalink
fix(firebase_auth): Fix PlatformException to `FirebaseAuthException…
Browse files Browse the repository at this point in the history
…` error message parsing (#11533)

* fix(firebase_auth): Fix `PlatformException` to `FirebaseAuthException` error message parsing

* Add new contributor to AUTHORS
  • Loading branch information
Isti01 committed Jan 9, 2024
1 parent cef006a commit 8fe8cfd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
3 changes: 2 additions & 1 deletion AUTHORS
Expand Up @@ -62,4 +62,5 @@ Markus Köhne <markus@koehne.dev>
Max Steffen <git@max-steffen.dev>
Mohd Faheem Ansari <codefaheem@gmail.com>
Om Phatak <everythingoutdated@gmail.com>
Liu Zhisong <liuzs0666@gmail.com>
Horváth István <horvatska01@gmail.com>
Liu Zhisong <liuzs0666@gmail.com>
Expand Up @@ -80,9 +80,15 @@ FirebaseException platformExceptionToFirebaseAuthException(
}
}

var parsedMessage = platformException.message?.split(': ').last;
if (parsedMessage?.endsWith(' ]') ?? false) {
// Fixes JSON response from Auth blocking function: https://github.com/firebase/flutterfire/issues/11532
parsedMessage = parsedMessage!.substring(0, parsedMessage.length - 2);
}

return FirebaseAuthException(
code: code,
message: platformException.message?.split(': ').last,
message: parsedMessage,
credential: credential,
email: email,
);
Expand Down
Expand Up @@ -30,6 +30,26 @@ void main() {
),
);
});

test(
'should catch a [PlatformException] and throw a [FirebaseException] with the correct message',
() async {
PlatformException platformException = PlatformException(
code: 'UNKNOWN',
message:
'An internal error has occurred. [ BLOCKING_FUNCTION_ERROR_RESPONSE:HTTP Cloud Function returned an error: {"error":{"details":"The user is not allowed to log in","message":"","status":"PERMISSION_DENIED"}} ]',
);

expect(
() => convertPlatformException(platformException, StackTrace.empty),
throwsA(
isA<FirebaseAuthException>()
.having((e) => e.code, 'code', 'BLOCKING_FUNCTION_ERROR_RESPONSE')
.having((e) => e.message, 'message',
'{"error":{"details":"The user is not allowed to log in","message":"","status":"PERMISSION_DENIED"}}'),
),
);
});
});

group('platformExceptionToFirebaseAuthException()', () {
Expand Down

0 comments on commit 8fe8cfd

Please sign in to comment.