Skip to content

Commit 25f9204

Browse files
authored
fix(database): improve error handling in platformExceptionToFirebaseException (#18007)
1 parent 92f03e0 commit 25f9204

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

packages/_flutterfire_internals/lib/src/exception.dart

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,27 @@ FirebaseException platformExceptionToFirebaseException(
3838
PlatformException platformException, {
3939
required String plugin,
4040
}) {
41-
Map<String, Object>? details = platformException.details != null
42-
? Map<String, Object>.from(platformException.details)
43-
: null;
41+
Map<String, Object>? details;
42+
43+
final rawDetails = platformException.details;
44+
45+
if (rawDetails is Map) {
46+
details = Map<String, Object>.from(rawDetails);
47+
}
4448

4549
String? code;
4650
String message = platformException.message ?? '';
4751

4852
if (details != null) {
49-
code = (details['code'] as String?) ?? code;
50-
message = (details['message'] as String?) ?? message;
53+
code = details['code'] as String?;
54+
message = details['message'] as String? ?? message;
55+
} else if (rawDetails != null) {
56+
message = rawDetails.toString();
5157
}
5258

5359
return FirebaseException(
5460
plugin: plugin,
55-
code: code,
61+
code: code ?? 'unknown',
5662
message: message,
5763
);
5864
}

0 commit comments

Comments
 (0)