Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: updating not found exception to give more information #12813

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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