diff --git a/packages/_flutterfire_internals/lib/src/exception.dart b/packages/_flutterfire_internals/lib/src/exception.dart index e9c543aa9132..8629f4ab3063 100644 --- a/packages/_flutterfire_internals/lib/src/exception.dart +++ b/packages/_flutterfire_internals/lib/src/exception.dart @@ -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( diff --git a/packages/cloud_firestore/cloud_firestore/example/integration_test/document_reference_e2e.dart b/packages/cloud_firestore/cloud_firestore/example/integration_test/document_reference_e2e.dart index b2312a3697f7..bdfc14399b03 100644 --- a/packages/cloud_firestore/cloud_firestore/example/integration_test/document_reference_e2e.dart +++ b/packages/cloud_firestore/cloud_firestore/example/integration_test/document_reference_e2e.dart @@ -525,6 +525,19 @@ void runDocumentReferenceTests() { isA() .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().having( + (e) => e.message, + 'message', + isNot(contains('Some requested document was not found')), + ), + ); } }, );