Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/_flutterfire_internals/lib/src/exception.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,19 @@ FirebaseException platformExceptionToFirebaseException(
String message = platformException.message ?? '';

if (details != null) {
print('platformException.code: ${platformException.code}');
print('platformException.details: ${platformException.details}');
print('platformException.message: ${platformException.message}');

code = (details['code'] as String?) ?? code;
message = (details['message'] as String?) ?? message;

if ((code?.compareTo('not-found') == 0) && message.contains('NOT_FOUND:')) {
/// For not-found exceptions, return the Firestore provided reason and
/// document path rather than generic error message.
message = message.split('NOT_FOUND:').last.trim();
} else {
message = (details['message'] as String?) ?? message;
}
}

return FirebaseException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,19 @@ void runDocumentReferenceTests() {
isA<FirebaseException>()
.having((e) => e.code, 'code', 'not-found'),
);

// https://github.com/firebase/flutterfire/pull/12813
// Use platformException.message, which is more detailed, rather than the
// platformException.details['message'] which is the generic:
// 'Some requested document was not found'
expect(
e,
isA<FirebaseException>().having(
(e) => e.message,
'message',
isNot(contains('Some requested document was not found')),
),
);
}
},
);
Expand Down