diff --git a/packages/cloud_functions/cloud_functions/CHANGELOG.md b/packages/cloud_functions/cloud_functions/CHANGELOG.md index 92877f421931..9cc42a27fe85 100644 --- a/packages/cloud_functions/cloud_functions/CHANGELOG.md +++ b/packages/cloud_functions/cloud_functions/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.5.1 + +* Fix for throwing `PlatformException` and `CloudFunctionsException`. + ## 0.5.0 * Fix example app build failure on CI (missing AndroidX Gradle properties). diff --git a/packages/cloud_functions/cloud_functions/lib/src/https_callable.dart b/packages/cloud_functions/cloud_functions/lib/src/https_callable.dart index b06a85831866..bf8845aa86da 100644 --- a/packages/cloud_functions/cloud_functions/lib/src/https_callable.dart +++ b/packages/cloud_functions/cloud_functions/lib/src/https_callable.dart @@ -27,9 +27,9 @@ class HttpsCallable { /// automatically includes a Firebase Instance ID token to identify the app /// instance. If a user is logged in with Firebase Auth, an auth ID token for /// the user is also automatically included. - Future call([dynamic parameters]) { + Future call([dynamic parameters]) async { try { - return CloudFunctionsPlatform.instance + return await CloudFunctionsPlatform.instance .callCloudFunction( appName: _cloudFunctions._app.name, region: _cloudFunctions._region, diff --git a/packages/cloud_functions/cloud_functions/pubspec.yaml b/packages/cloud_functions/cloud_functions/pubspec.yaml index 2f4180042f11..e1c550eea425 100644 --- a/packages/cloud_functions/cloud_functions/pubspec.yaml +++ b/packages/cloud_functions/cloud_functions/pubspec.yaml @@ -1,6 +1,6 @@ name: cloud_functions description: Flutter plugin for Cloud Functions. -version: 0.5.0 +version: 0.5.1 homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/cloud_functions/cloud_functions flutter: diff --git a/packages/cloud_functions/cloud_functions/test/cloud_functions_test.dart b/packages/cloud_functions/cloud_functions/test/cloud_functions_test.dart index c9271d78208e..3c77bce58855 100644 --- a/packages/cloud_functions/cloud_functions/test/cloud_functions_test.dart +++ b/packages/cloud_functions/cloud_functions/test/cloud_functions_test.dart @@ -84,5 +84,40 @@ void main() { ], ); }); + + group('exception', () { + test('$CloudFunctionsException', () { + MethodChannelCloudFunctions.channel + .setMockMethodCallHandler((MethodCall methodCall) async { + throw PlatformException( + code: 'functionsError', + message: 'Cloud function failed with exception.', + details: { + 'code': 'INTERNAL', + 'details': null, + 'message': 'Error: foo bar...' + }); + }); + + expect(() async { + await CloudFunctions.instance + .getHttpsCallable(functionName: 'function-causes-error') + .call(); + }, throwsA(isA())); + }); + + test('Exception', () { + MethodChannelCloudFunctions.channel + .setMockMethodCallHandler((MethodCall methodCall) async { + throw PlatformException(code: 'something wrong'); + }); + + expect(() async { + await CloudFunctions.instance + .getHttpsCallable(functionName: 'function-causes-error') + .call(); + }, throwsA(isA())); + }); + }); }); }