Skip to content

[cloud_functions] Throws CloudFunctionsException in right cases #2556

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

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 4 additions & 0 deletions packages/cloud_functions/cloud_functions/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<HttpsCallableResult> call([dynamic parameters]) {
Future<HttpsCallableResult> call([dynamic parameters]) async {
try {
return CloudFunctionsPlatform.instance
return await CloudFunctionsPlatform.instance
.callCloudFunction(
appName: _cloudFunctions._app.name,
region: _cloudFunctions._region,
Expand Down
2 changes: 1 addition & 1 deletion packages/cloud_functions/cloud_functions/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CloudFunctionsException>()));
});

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<Exception>()));
});
});
});
}